当前位置:网站首页>Several important functional operations of general two-way circular list
Several important functional operations of general two-way circular list
2022-08-09 16:17:00 【Yellow duck 233】
Creation of doubly circular linked list
struct DNode{struct DNode* prev; //point to the previous nodestruct DNode* next; //point to the next nodechar elem[]; // use a flexible array to accept any type};Insert before the node, insert after the node and delete the node in the doubly circular linked list
//Insert before nodevoid insert_before(struct DNode* node, const void* pElem, size_t elemSize){assert(node!=NULL && pelem!=NULL && elemsize!=0);//Because a flexible array is used, the size of the inserted data must be added to allocate memorystruct DNode* insNode = (struct DNode*)malloc(sizeof(struct DNode) + elemSize);if(insNode == NULL)return;insNode->next = node;insNode->prev = node->prev;memcpy(node->elem, pElem, elemSize); //Because we don't know the type of elem, we use memory copynode->prev->next = insNode; //The order of these two sentences cannot be chaoticnode->prev = insNode;}//Insert after node, there is not much difference from the above, just change a few wordsvoid insert_after(struct DNode* node, const void* pElem, size_t elemSize){assert(node!=NULL && pelem!=NULL && elemsize!=0);//Because a flexible array is used, the size of the inserted data must be added to allocate memorystruct DNode* insNode = (struct DNode*)malloc(sizeof(struct DNode) + elemSize);if(insNode == NULL)return;insNode->next = node->next;insNode->prev = node;memcpy(node->elem, pElem, elemSize);node->next->prev = insNode; //The order of these two sentences cannot be disorderednode->next = insNode;}// delete nodevoid delete_dnode(struct DNode* node){assert(node != NULL);if(node->next = node) //If node is the head node, why can't it be deletedreturn;node->prev->next = node->next;node->next->prev = node->prev;free(node);}//create a header nodestruct DNode* create_cdlist(void){//Because the head node does not store data, you can directly allocate the memory of the size of the structurestruct DNode* list = (struct DNode*)malloc(sizeof(struct DNode));if(list != NULL) //If the creation fails, return NULL directly{list->next = list;list->prev = list; //There is no data at the beginning and it is a ring, so it points to itself first}return list;}//Get the posth node, pos starts from 1struct DNode* get_dnode(struct DNode* list, size_t pos){assert(list != NULL);struct DNode* node = list->next;size_t i;for(i = 1; inext);if(i < pos) //When pos is greater than the total length of the linked list, node has already looped and exited the loop and pointed to the head node,// this time return emptyreturn NULL;return node;} 边栏推荐
- redis6在centos7的安装
- docker安装seata(指定配置文件、数据库、容器数据卷等)
- 如何通过股票量化交易接口实现盈利稳定?
- JVM简学笔记
- DSPE-PEG-Hydrazide, DSPE-PEG-HZ, Phospholipid-Polyethylene Glycol-Hydrazide MW: 1000
- OpenSSF's open source software risk assessment tool: Scorecards
- 如何让你的量化交易系统具有概率优势,具有正向收益预期呢?
- How can I know if quantitative programmatic trading is effective?
- 浅谈ArraryList的浅克隆和深克隆
- [MySql]实现多表查询-一对一,一对多
猜你喜欢

redis6在centos7的安装

focal loss原理及简单代码实现
![[MySql] implement multi-table query - one-to-one, one-to-many](/img/7e/8f1af4422a394969b28a553ead2c42.png)
[MySql] implement multi-table query - one-to-one, one-to-many

What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.

Shell programming loop statement

docker安装单机版redis、集群版redis

C#轻量级ORM使用 Dapper+Contrib

Simple analysis of regularization principle (L1 / L2 regularization)

经典面试题 之 TCP 三次握手/ 四次挥手

相干光(光学)
随机推荐
几何光学简介
pytorch从零搭建神经网络实现多分类(训练自己的数据集)
方法学习笔记
FilenameFilter filters filenames
如何保证电脑硬盘格式化后数据不能被恢复?
docker安装单机版redis、集群版redis
C#轻量级ORM使用 Dapper+Contrib
Talking about quantitative trading and programmatic trading
内存泄露检测工具VLD(Visual Leak Detector)使用说明
focal loss原理及简单代码实现
【小白必看】初始C语言(上)
如何通过通达信量化交易接口达到长期的收益?
How to achieve stable profit through the stock quantitative trading interface?
【超级账本开发者系列】专访——肖慧 : 不忘初心,方得始终
UDP多线程实现聊天
bin document read and write
EasyExcel的应用
怎么用VS+Qt创建新项目
浅谈一下量化交易与程序化交易
经典面试题 之 SQL优化