当前位置:网站首页>Two way leading circular linked list (C language)
Two way leading circular linked list (C language)
2022-06-11 23:05:00 【Xiaobai】
List.h
#pragma once
#include<stdio.h>
#include<stdlib.h>
typedef int LTDataType;
typedef struct ListNode
{
LTDataType data;
struct ListNode* next;
struct ListNode* prev;
}ListNode;
ListNode* BuyListNode(LTDataType x);
ListNode* ListInit();
void ListPrint(ListNode* pHead);
void ListPushBack(ListNode* pHead, LTDataType x);
void ListPopBack(ListNode* pHead);
void ListPushFront(ListNode* pHead, LTDataType x);
void ListPopFront(ListNode* pHead);
ListNode* ListFind(ListNode* pHead, LTDataType x);
void ListInsert(ListNode* pos, LTDataType x);
void ListErase(ListNode* pos);
void ListDestory(ListNode* pHead);
List.c
#include"List.h"
ListNode* BuyListNode(LTDataType x)
{
ListNode* node = (ListNode*)malloc(sizeof(ListNode));
node->data = x;
return node;
}
ListNode* ListInit()
{
ListNode* plist = BuyListNode(-1);
plist->next = plist;
plist->prev = plist;
return plist;
}
void ListPrint(ListNode* pHead)
{
ListNode* cur = pHead->next;
while (cur != pHead)
{
printf("%d ", cur->data);
cur = cur->next;
}
printf("\n");
}
void ListPushBack(ListNode* pHead, LTDataType x)
{
ListNode* newnode = BuyListNode(x);
pHead->prev->next = newnode;
newnode->prev = pHead->prev;
newnode->next = pHead;
pHead->prev = newnode;
}
void ListPopBack(ListNode* pHead)
{
ListNode* del = pHead->prev;
pHead->prev = del->prev;
del->prev->next = pHead;
free(del);
}
void ListPushFront(ListNode* pHead, LTDataType x)
{
ListNode* newnode = BuyListNode(x);
pHead->next->prev = newnode;
newnode->next = pHead->next;
newnode->prev = pHead;
pHead->next = newnode;
}
void ListPopFront(ListNode* pHead)
{
ListNode* del = pHead->next;
pHead->next = del->next;
del->next->prev = pHead;
free(del);
}
ListNode* ListFind(ListNode* pHead, LTDataType x)
{
ListNode* cur = pHead->next;
while (cur != pHead)
{
if (cur->data == x)
return cur;
cur = cur->next;
}
return NULL;
}
void ListInsert(ListNode* pos, LTDataType x)
{
ListNode* newnode = BuyListNode(x);
pos->prev->next = newnode;
newnode->prev = pos->prev;
newnode->next = pos;
pos->prev = newnode;
}
void ListErase(ListNode* pos)
{
pos->prev->next = pos->next;
pos->next->prev = pos->prev;
free(pos);
}
void ListDestory(ListNode* pHead)
{
ListNode* cur = pHead->next;
while (cur != pHead)
{
ListNode* next = cur->next;
free(cur);
cur = next;
}
free(pHead);
}
边栏推荐
- Si4432 RF chip scheme typical application of data transmission of wireless communication module of Internet of things
- Huawei cloud, OBS
- Altium designer工程下多个原理图和PCB图的一一对应
- Tensorflow [actual Google deep learning framework] uses HDF5 to process large data sets with tflearn
- [technology sharing] after 16 years, how to successfully implement the dual active traffic architecture of zhubajie.com
- postgresql10 進程
- Is the product stronger or weaker, and is the price unchanged or reduced? Talk about domestic BMW X5
- Only three steps are needed to learn how to use low code thingjs to connect with Sen data Dix data
- 动态规划之0-1背包问题(详解+分析+原码)
- Using the command line to call shell in unity
猜你喜欢
![[day4 literature intensive reading] space – time interdependence: evidence against Asymmetric mapping between time and space](/img/ce/f3817690a024cfebcf58a5ccc3cfdc.png)
[day4 literature intensive reading] space – time interdependence: evidence against Asymmetric mapping between time and space
![[Day2 intensive literature reading] time in the mind: using space to think about time](/img/7a/b155ee0c136f911a7e99e9633af246.png)
[Day2 intensive literature reading] time in the mind: using space to think about time

Computer forced shutdown Oracle login failed

Google搜索为什么不能无限分页?

Google搜索為什麼不能無限分頁?

Library management system

Altium designer工程下多个原理图和PCB图的一一对应
![[day15 literature extensive reading] numerical magnetic effects temporary memories but not time encoding](/img/57/9ce851636b927813a55faedb4ecd48.png)
[day15 literature extensive reading] numerical magnetic effects temporary memories but not time encoding

Pourquoi Google Search ne peut - il pas Pager indéfiniment?

The top ten trends of 2022 industrial Internet security was officially released
随机推荐
机器学习之数据处理与可视化【鸢尾花数据分类|特征属性比较】
Small program startup performance optimization practice
Correcting high score phrases & sentence patterns
Method for WiFi wireless transmission module to access cloud platform using esp8266 chip scheme
Games-101 闫令琪 5-6讲 光栅化处理 (笔记整理)
Exercise 11-2 find week (15 points)
Exercise 11-3 calculate the longest string length (15 points)
The remote connection to redis is disconnected and reconnected after a while
postgresql10 进程
Meetup review how Devops & mlops solve the machine learning dilemma in enterprises?
华为设备配置HoVPN
【Day13-14 文献精读】Cross-dimensional magnitude interactions arise from memory interference
[Delphi] determine the encoding method of the file (ANSI, Unicode, utf8, unicodebig)
Google搜索為什麼不能無限分頁?
Jsonparseexception: unrecognized token 'username': was expecting error when submitting login data
产品力进阶新作,全新第三代荣威RX5盲订开启
PHP+MYSQL图书管理系统(课设)
Computer forced shutdown Oracle login failed
基于模板配置的数据可视化平台
Unity3d C#开发微信小游戏音频/音效播放问题解决过程分享