当前位置:网站首页>Chained storage of queues
Chained storage of queues
2022-07-01 12:22:00 【Between the steps】
Chain storage of queues
1. initialization
#include<stdio.h>
typedef struct LinkNode{
ElemType data;
struct LinkNode *next;
}LinkNode;
typedef struct{
LinkNode *front,*rear;
}LinkQueue;
// Initialize queue , Leading node
void InitQueue(LinkQueue &Q){
// On initialization ,front and rear All point to the head node
Q.front=Q.rear=(LinkNode*)malloc(sizeof(LinkNode));
Q.front->next=NULL;
}
void testLinkQueue(){
LinkQueue Q; // Declare a queue
InitQueue(Q); // Initialize queue
// Follow up operation
}

2. Is it empty
bool isEmpty(LinkQueue Q){
if(Q.rear==Q.front)
return true;
else
return false;
}
3. Do not lead the node to initialize the queue
// Initialize queue , No leading node
void InitQueue(LinkQueue &Q){
// On initialization ,front and rear All point to NULL
Q.front=NULL;
Q.rear=NULL;
}
4. Don't take the lead in judging empty nodes
bool isEmpty(LinkQueue Q){
if(Q.front==NULL)
return true;
else
return false;
}
5. Joining operation ( Leading node ) Similar to tail interpolation
void EnQueue(LinkQueue &Q,ElemType x){
LinkNode *s=(LinkNode*)malloc(sizeof(LinkNode));
s.data=x;
s->next=NULL;
Q.rear->next=s; // New node insertion rear after
Q.rear=s; // Modify the tail pointer
}

6. Join the team without taking the lead ( Maybe there are elements in it Maybe an empty element is inserted )
// New elements in the team No leading node
void EnQueue(LinkQueue &Q,ElemType x){
LinkNode *s=(LinkNode*)malloc(sizeof(LinkNode)); // Open up space to store new elements
s->data=x; // The inserted value is put into the newly opened space
s->next=NULL; // The newly opened space points to NULL
if(Q.front==NULL){
// There is no element There is no head node Only Q.front and Q.rear The pointer
Q.front=s;
Q.rear=s;
}
else{
Q.rear->next=s;
Q.rear=s;
}
}

7. Out of line operation ( Leading node )
bool DeQueue(LinkQueue &Q,ElemType &x){
if(Q.front==Q.rear) // Description is empty stack
return false;
LinkNode *p=Q.front->next; //p Point to the first node
x=p->data; // With variable x Return to team leader element
Q.front->next=p->next; // Modify the header node next The pointer
if(Q.rear==p){
// The last node comes out of the stack
Q.rear=Q.front; // modify rear The pointer
}
free(p);
return true;
}


8. Do not take the lead in the out of line operation of the node
bool DeQueue(LinkQueue &Q,ElemType &x){
if(Q.front==NULL) // Description is empty stack
return false;
LinkNode *p=Q.front; //p Point to the node out of the queue
x=p->data; // Variable x Returns the header element
Q.front=p->next; // modify front The pointer
if(Q.rear==p){
// The last node comes out of the stack
Q.front=NULL;
Q.rear=NULL;
}
free(p);
return true;
}

Chain storage does not consider the situation of full queues
边栏推荐
- Use set_ Handler filters out specific SystemC wrapping & error messages
- Onenet Internet of things platform - mqtt product devices send messages to message queues MQ
- Understanding of NAND flash deblocking
- 迅为i.MX8Mmini开发板离线构建Yocto系统
- 栈-------
- Friends day 2022
- 研发效能度量框架解读
- GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
- Sum of factor numbers of interval product -- prefix sum idea + fixed one shift two
- Ansible相关内容梳理
猜你喜欢

I wish you all a happy reunion

谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征

【datawhale202206】pyTorch推荐系统:召回模型 DSSM&YoutubeDNN
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5](/img/f5/9c68b3dc30362d3776c262fdc13fd0.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5

【单片机】【数码管】数码管显示

【datawhale202206】pyTorch推荐系统:多任务学习 ESMM&MMOE

被锡膏坑了一把
![[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn](/img/f2/7931952b832e84d7b8f2615906f33f.png)
[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn

Chapter 14 signals (IV) - examples of multi process tasks
![[speech signal processing] 3 speech signal visualization -- prosody](/img/06/5f57f9dfe3a0f2f70022706f7d4d17.jpg)
[speech signal processing] 3 speech signal visualization -- prosody
随机推荐
Consolidate -c operator
MQ-防止消息丢失及重复消费
Virtualenv+pipenv virtual environment management
[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
Why does the JVM heap memory exceed 32g and pointer compression fail?
Sum of factor numbers of interval product -- prefix sum idea + fixed one shift two
2022-06-28-06-29
Summary of JFrame knowledge points 2
C serialization simple experiment
谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
Leetcode force buckle (Sword finger offer 31-35) 31 Stack push pop-up sequence 32i II. 3. Print binary tree from top to bottom 33 Post order traversal sequence 34 of binary search tree The path with a
Self organization is the two-way rush of managers and members
Golang des-cbc
Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/
91. (cesium chapter) cesium rocket launch simulation
Good luck brought by years of persistence
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
Ipv6-6to4 experiment
研发效能度量框架解读
Interpretation of R & D effectiveness measurement framework