当前位置:网站首页>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;} 边栏推荐
- OpenCV简介与搭建使用环境
- What drives the development of quantitative trading interfaces?
- How to create a new project with VS+Qt
- 分析:通过哪种方法来建立股票量化交易数据库?
- Database multi-table link query method
- 怎么用VS+Qt创建新项目
- How do quantitative investors obtain real-time market data?
- Simple analysis of regularization principle (L1 / L2 regularization)
- How to flexibly use the advantages of the quantitative trading interface to complement each other?
- Shell functions and arrays
猜你喜欢
随机推荐
英语议论文读写02 Engineering
DSPE-PEG-Hydrazide, DSPE-PEG-HZ, Phospholipid-Polyethylene Glycol-Hydrazide MW: 1000
VS2010: devenv.sln solution save dialog appears
职业量化交易员对量化交易有什么看法?
Qt对话框中show和exec的区别
focal loss原理及简单代码实现
量化投资者是如何获取实时行情数据的呢?
pytorch从零搭建神经网络实现多分类(训练自己的数据集)
OpenCV - Matrix Operations Part 3
SNR 信噪比
How can I know if quantitative programmatic trading is effective?
MySQL principle and optimization: Limit the query optimization
经典面试题 之 JVM调优
异常学习笔记
浅谈一下量化交易与程序化交易
How to achieve long-term benefits through the Tongdaxin quantitative trading interface?
量化程序化交易都有哪些热点争议?
相干光(光学)
How to create a new project with VS+Qt
Shell functions and arrays









