当前位置:网站首页>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;
}
边栏推荐
- 虚拟偶像的歌声原来是这样生成的!
- 广东财政多举措助力稳住粮食安全“压舱石”
- Guangdong's finance has taken many measures to help stabilize the "ballast stone" of food security
- 孤独的年轻人,戒不了Jellycat
- Watermelon book chapter 3 (first & second)
- 20210419 combined sum
- (07) flask is OK if you have a hand -- flask Sqlalchemy
- 5V boost 9V chip
- USB network card drive data stream
- 象棋机器人「弄折了」棋童的手指。。。
猜你喜欢

go 用本地代码replace

STS下载教程(include官网无法下载解决方案)

About the problem that the onapplicationevent method of the custom listener is executed multiple times

最强分布式锁工具:Redisson

上半年火灾起数下降27.7%,广东将这样提升全民消防安全素质

解决方案:Can not issue executeUpdate() or executeLargeUpdate() for SELECTs

阿里云云数据库RDS版Exception during pool initialization

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

Fundamentals of mathematics 01

评价自动化测试优劣的隐性指标
随机推荐
2021-3-22-tencent - minimum number of guards
Go Beginner (5)
CLS 监控告警:实时保障线上服务高可用性
5V boost 9V chip
图像分割 vs Adobephotoshop(PS)
Bishi journey
2021-3-23-meituan-regular sequence
Go Beginner (4)
When the script runs in the background, it redirects the log from the console to its own named file
解决方案:idea project没有显示树状图
【产品】关于微信产品分析
POJ1611_The Suspects
mysql分页查询实例_mysql分页查询实例讲解「建议收藏」
Complete data summary of lapsus$apt organization that stole Microsoft's source code in March 2022
Plus SBOM: assembly line BOM pbom
Binary search decision tree (average search length of binary search tree)
Go replace with local code
象棋机器人「弄折了」棋童的手指。。。
@Postconstruct annotations and initializingbean perform some initialization operations after bean instantiation
B 站 713 事故后的多活容灾建设|TakinTalks 大咖分享