当前位置:网站首页>Chain representation and implementation of queues
Chain representation and implementation of queues
2022-07-27 12:26:00 【InfoQ】
typedef struct LinkNode{ // Chain queue node
ElemType data;
struct LinkNode *next;
}LinkNode;
typedef struct{ // Chain queues
LinkNode *front, *rear // The head and tail pointers of the queue
}LinkQueue;
// Initialize queue ( Leading node )
void InitQueue(LinkQueue &Q){
// initialization front、rear All point to the head node
Q.front = Q.rear = (LinkNode*)malloc(sizeof(LinkNode));
Q.front -> next = NULL;
}
viod testLinkQueue(){
LinkQueue Q; // Declare a queue
InitQueue(Q); // Initialize queue
}
// Determines if the queue is empty
bool IsEmpty(LinkQueue Q){
if(Q.front == Q.rear){
return true;
}else{
return false;
}
}
typedef struct LinkNode{ // Chain queue node
ElemType data;
struct LinkNode *next;
}LinkNode;
typedef struct{ // Chain queues
LinkNode *front, *rear // The head and tail pointers of the queue
}LinkQueue;
// New elements in the team ( Leading node )
void EnQueue(LinkQueue &Q, ElemType x){
LinkNode *s = (LinkNode *)malloc(sizeof(LinkNode));
s->data = x;
s->next = NULL;
Q.rear->next = s; // Insert new node into rear after
Q.rear = s; // Modify the tail pointer
}
Out of line operation
typedef struct LinkNode{ // Chain queue node
ElemType data;
struct LinkNode *next;
}LinkNode;
typedef struct{ // Chain queues
LinkNode *front, *rear // The head and tail pointers of the queue
}LinkQueue;
// Team head element out of team operation ( Leading node )
bool DEQueue(LinkQueue &Q, ElemType &x){
if(Q.front == Q.rear){
return // Empty queue
}
LinkNode *p = Q.front->next;
x = p->data; // With variable x Return to team leader element
Q.front->nexy = p->nexy; // Modify the header node next The pointer
if(Q.rear == p){ // This is the last node out of the team
Q.rear = Q.front // modify rear The pointer
}
free(p); // Release node space
return true;
}
边栏推荐
- 2021-3-19-byte-face value
- 开关量输入输出模块DAM-5055
- Good looking (dynamic) Jay fan self-made dynamic album card (front and back are different) and lyrics page
- Makefile template
- The song of the virtual idol was originally generated in this way!
- 20210422 consolidation interval
- Binary search decision tree (average search length of binary search tree)
- Advance in the flutter project_ image_ Picker component usage
- 快抖抢救“失意人”
- Fundamentals of mathematics 02 - sequence limit
猜你喜欢
![[database data recovery] a data recovery case in which the disk partition where the SQL Server database is located is insufficient and an error is reported](/img/8a/478209854cb5ce139afc338d106d36.png)
[database data recovery] a data recovery case in which the disk partition where the SQL Server database is located is insufficient and an error is reported

Fundamentals of mathematics 02 - sequence limit

图像分割 vs Adobephotoshop(PS)

Play CSDN editor

Solution: can not issue executeupdate() or executelargeupdate() for selections

J9 number theory: how long is the mainstreaming of decentralized identity?
Do you really understand the underlying data structure skip list of Zset in redis?

我在英国TikTok做直播电商

20210518-Cuda

Implicit indicators for evaluating the advantages and disadvantages of automated testing
随机推荐
CLS 监控告警:实时保障线上服务高可用性
V-show failure
Configuration files in MySQL
The strongest distributed locking tool: redisson
你尚未连接代理服务器可能有问题或地址不正确(如何查看代理服务器ip)
Flash quickly builds an API
matlab二分法例题(用二分法求零点例题)
B 站 713 事故后的多活容灾建设|TakinTalks 大咖分享
Plus版SBOM:流水线物料清单PBOM
硬刚甲方后:中国移动 4908 万大单被废
The use of omitempty in go
Kazoo tutorial
Unity 2D game tutorial
Go Introduction (2)
Unity shader - Laser special effect shader[easy to understand]
广东财政多举措助力稳住粮食安全“压舱石”
Guangdong's finance has taken many measures to help stabilize the "ballast stone" of food security
STS下载教程(include官网无法下载解决方案)
mysql分页查询实例_mysql分页查询实例讲解「建议收藏」
20210520 TCP sliding window