当前位置:网站首页>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;
}
边栏推荐
- (07) flask is OK if you have a hand -- flask Sqlalchemy
- 【数据库数据恢复】SQL Server数据库所在磁盘分区空间不足报错的数据恢复案例
- Play CSDN editor
- J9 number theory: how long is the mainstreaming of decentralized identity?
- About offline caching application cache / using manifest file caching
- 图像分割 vs Adobephotoshop(PS)
- 最强分布式锁工具:Redisson
- In the first half of the year, the number of fires decreased by 27.7%. Guangdong will improve the fire safety quality of the whole people in this way
- Unity Shader 一 激光特效Shader[通俗易懂]
- Several rounds of SQL queries in a database
猜你喜欢

Watermelon book chapter 3 (first & second)

Fundamentals of mathematics 01

Iptables firewall

严控室外作业时间!佛山住建局发文:加强高温期间建筑施工安全管理

Complete data summary of lapsus$apt organization that stole Microsoft's source code in March 2022
Do you really understand the underlying data structure skip list of Zset in redis?

Go replace with local code

广东:剧本杀等新行业新业态场所,消防安全监管不再“缺位”

快抖抢救“失意人”

图像分割 vs Adobephotoshop(PS)
随机推荐
你尚未连接代理服务器可能有问题或地址不正确(如何查看代理服务器ip)
go 用本地代码replace
配置更改删除了路由过滤器,分布路由器不堪重负:加拿大网络大瘫痪
After Party A's hard work, 49.08 million orders of China Mobile were scrapped
5V升压9V芯片
NewTicker使用
[product] about wechat product analysis
Multi activity disaster recovery construction after station B 713 accident | takintalks share
Bishi journey
mysql8msi安装教程(数据库mysql安装教程)
mysql分页查询实例_mysql分页查询实例讲解「建议收藏」
kazoo使用教程
Recursive method | Fibonacci sequence
2021-3-23-meituan-priority queue
One article to understand the index of like in MySQL
Unity shader - Laser special effect shader[easy to understand]
20210419 combined sum
deeplab系列详解(简单实用年度总结)
Current situation and development trend of accounting computerization
Go Introduction (2)