当前位置:网站首页>Chain queue
Chain queue
2022-07-23 11:59:00 【Look, that's a licking dog】
#include <stdio.h>
#include <malloc.h>
typedef int T;
typedef struct QNode
{
T data;// data
QNode* next;// Point to the next node
}*Node;
typedef struct
{
Node front, rear;// head 、 Tail pointer
int count;// Counter
}*LinkQuene;
bool InitQuene(LinkQuene q)// initialization
{
q->front = q->rear = (Node)malloc(sizeof(Node));
q->front->next = NULL;
q->count = 0;
return true;
}
bool DetoryQuene(LinkQuene Q)// The destruction
{
while (Q->front)
{
Q->rear = Q->front->next;
free(Q->front);
Q->front = Q->rear;
}
Q->count = 0;
return true;
}
bool ClearQuene(LinkQuene Q)// Qingdui
{
Node p, q;
Q->rear = Q->front;
p = Q->front;
Q->front->next = NULL;
while (p)
{
q = p->next;
free(p);
p = q;
}
Q->count = true;
return true;
}
bool Is_Empty(LinkQuene Q)// Sentenced to empty
{
return Q->front == Q->rear;
}
int GetLength(LinkQuene q)// The queue length
{
return q->count;
}
T GetHead(LinkQuene q)// Head element
{
return q->front->next->data;
}
bool Push(LinkQuene q, T val)// The team
{
if (!q)
return false;
Node node = (Node)malloc(sizeof (Node));
node->data = val;
node->next = NULL;
q->rear->next = node;
q->rear = node;
q->count++;
return true;
}
T Pop(LinkQuene Q)// Out of the team
{
if (!Q)
return false;
Node p;
T tmp;
p = Q->front->next;
tmp = p->data;
Q->front->next = p->next;
if (p == Q->rear)
Q->rear = Q->front;
//free(p);
Q->count--;
return true;
}
void Show(LinkQuene Q)// Traverse
{
Node p;
p = Q->front->next;
while (p)
{
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
int main()
{
LinkQuene Q = (LinkQuene)malloc(sizeof(LinkQuene));
InitQuene(Q);
for (int i = 1; i <= 5; i++)
{
Push(Q, i);
}
Show(Q);
printf("Head: %d\n", GetHead(Q));
printf("Len: %d\n", GetLength(Q));
printf("Pop: %d\n", Pop(Q));
return 0;
}
边栏推荐
- UE4解决WebBrowser无法播放H.264的问题
- Upload pictures to qiniu cloud through the web call interface
- SQL realizes the user statistics of continuous login for more than 7 days
- [monitoring deployment practice] display the charts of Prometheus and loki+promtail based on granfana
- The user logs in continuously (interruption is allowed) to query SQL
- MySQL backup
- 静态链表
- 9、 Practical class
- NT68661-屏参升级-RK3128-开机自己升级屏参
- MySQL storage engine
猜你喜欢
随机推荐
两个栈共用空间
pytorch与paddlepaddle对比——以DCGAN网络实现为例
The user logs in continuously (interruption is allowed) to query SQL
强迫症的硬盘分区
Adding environment variables and templates to systemctl service
Charles抓包的使用步骤
Data warehouse 4.0 notes - Data Warehouse Modeling
飞桨高层API实现人脸关键点检测
ADB common commands
数仓4.0笔记——用户行为数据采集一
[hudi]hudi compilation and simple use of Hudi & spark and Hudi & Flink
MySQL password free login settings
11、多线程
Standardize database design
MySQL index
使用makefile编译ninja
[doris] configure and basically use the contents system (continue to add content when you have time)
Lecturer solicitation order | Apache dolphin scheduler meetup sharing guests, looking forward to your topic and voice!
Ten year structure five year life-01 at the beginning of graduation
Image fuzzy processing batch production fuzzy data set








