当前位置:网站首页>Chained queue push and pop related operations
Chained queue push and pop related operations
2022-08-08 07:03:00 【Nine-tailed cat】
About the chain queue, it mainly has the following characteristics:
1. The chained queue pointer field has two pointers front and rear, which point to the head node and the last node of the linked list respectively
2. The chain queue can only enter at one end and exit at one end
3. There is no limit to the number of members in the chain queue
The following is the specific implementation of related functions:
1. The overall linked list queue function is as follows:
#ifndef _LINKQ_H#define _LINKQ_Htypedef int Data_t;typedef struct node// is used to store member information of linked list elements and to connect linked lists{Data_t data;struct node *next;}Node;typedef struct linkqueue//Due to pointing to the head and tail of the queue{struct node *front;//The head node of the chain queuestruct node *rear;//The end node of the chain queue}Linkq;//create queueLinkq *create_linkq();// Emptyint linkq_is_empty(Linkq *q);// enqueuevoid enlinkq(Linkq *q, Data_t data);//dequeuevoid delinkq(Linkq *q, Data_t *data);#endif2. Linked list queue creation function:
Linkq *create_linkq(){Node *head = (Node *)malloc(sizeof(Node));if(NULL == head){printf("Node malloc is failed\n");return NULL;}head->data = -1;head->next = NULL;Linkq *Q = (Linkq *)malloc(sizeof(Linkq));if(NULL == head){printf("Link Node malloc is failed\n");return NULL;}Q->front = head;Q->rear = head;return Q;}3. Perform an empty operation on the linked list to facilitate subsequent operations such as popping the stack
int linkq_is_empty(Linkq *Q){if(Q->front == Q->rear){return 1;}return 0;}4. Push operation of linked list queue
void enlinkq(Linkq *Q, Data_t data){Node *new = (Node *)malloc(sizeof(Node));if(NULL == new){printf("new malloc is failed\n");return;}new->next = Q->rear->next;Q->rear->next = new;new->data = data;printf("%d ", Q->front->next->data);}5. Pop operation of linked list queue
//Pop stackvoid delinkq(Linkq *Q, Data_t *data){linkq_is_empty(Q);*data = Q->front->next->data;Node *del = Q->front->next;Q->front->next = Q->front->next->next;free(del);del = NULL;}边栏推荐
猜你喜欢
随机推荐
DesignWare_APB_GPIO模块DUT&Testbench仿真
vlan路由配置
Food Industry Report: Research Analysis and Development Prospect Forecast of Chili Market
MongoDB的备份与恢复
P20 美颜相机的实现——基础铺垫2
Map和Set
P02 线程的用途
顺序循环队列的创建和基本应用
什么是原型图设计?
NVIDIA CUDA 高度并行处理器编程(四):性能优化习题
redis笔记
MySQL表的增删改查
Lettcode链表OJ题分享以及讲解
PURE(A Frustratingly Easy Approach for Entity and Relation Extraction)
TextCNN实现imdb数据集情感分类任务
RCNN目标检测原文理解
关系抽取论文阅读笔记
【EagleEye】2020-ECCV-EagleEye: Fast Sub-net Evaluation for Efficient Neural Network Pruning-论文详解
C语言-文件中标准IO的常用函数总结
神经网络预测值几乎一样,神经网络为什么能预测









