当前位置:网站首页>Queue (C language / linked list)
Queue (C language / linked list)
2022-04-23 08:24:00 【AuroraN】
Store the queue with a linked list , The principle is to put two head pointers and tail pointers , Add elements at the end of the team , Delete elements at the head of the team , Understand this principle , Just consider the special circumstances , For example, if there is no element in the queue after deleting an element, point the head pointer and tail pointer to null in time , The rest depends on the code
#include<stdio.h>
#include<windows.h>
typedef struct LinkLNode
{
int data;
struct LinkLNode* next;
}LinkLNode;
typedef struct
{
LinkLNode* rear;
LinkLNode* front;
int item;
}LinkQueue;
void Init(LinkQueue &Q){
LinkLNode* s;
s=(LinkLNode*)malloc(sizeof(LinkLNode));
Q.front=NULL;
Q.rear=NULL;
Q.item=0;
}
bool IsEmpty(LinkQueue Q){
if(Q.front==NULL)
return true;
else
return false;
}
void EnQueue(LinkQueue &Q,int n){
LinkLNode* s;
s=(LinkLNode*)malloc(sizeof(LinkLNode));
s->data=n;
s->next=NULL;
if(IsEmpty(Q)){
Q.front=s;
}else{
Q.rear->next=s;
}
Q.rear=s;
Q.item++;
}
void DeQueue(LinkQueue &Q){
if(IsEmpty(Q)){
return;
}
LinkLNode* s;
s=Q.front;
Q.front=Q.front->next;
free(s);
if(Q.item==0){
Q.front=NULL;
Q.rear=NULL;
}
}
void printQueue(LinkQueue Q){
LinkLNode* i=(LinkLNode*)malloc(sizeof(LinkLNode));
i=Q.front;
while(i!=NULL){
printf("%d\n",i->data);
i=i->next;
}
}
int main()
{
LinkQueue Q;
Init(Q);
int n;
int a[10];
scanf("%d",&n);
for (int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
EnQueue(Q,a[i]);
}
printQueue(Q);
printf("***\n");
DeQueue(Q);
printQueue(Q);
system("pause");
return 0;
}
版权声明
本文为[AuroraN]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230742497798.html
边栏推荐
- js将树形结构数据转为一维数组数据
- ajax防止缓存方法
- 谈谈那些基础但不简单的股票数据
- vslam PPT
- The simple problem of leetcode is to calculate the numerical sum of strings
- Qtablewidget header customization and beautification developed by pyqt5 (with source code download)
- A simple theme of Typecho with beautiful appearance_ Scarfskin source code download
- 常用正则表达式
- Data deletion and modification (MySQL)
- 通过实现参数解析器HandlerMethodArgumentResolver接口来自定义注解
猜你喜欢

Community group purchase applet source code + interface DIY + nearby leader + supplier + group collage + recipe + second kill + pre-sale + distribution + live broadcast

【解释】get ORA-12838: cannot read/modify an object after modifying it in parallel

扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...

一键清理项目下pycharm和Jupyter缓存文件

数据可视化:使用Excel制作雷达图

Goland 调试go使用-大白记录

My heart's broken! A woman's circle of friends envied others for paying wages on time and was fired. Even her colleagues who liked her were fired together

How to read books and papers

怎么读书读论文

LeetCode简单题之计算字符串的数字和
随机推荐
SYS_CONNECT_BY_PATH(column,'char') 结合 start with ... connect by prior
ApplicationReadyEvent的使用
Data deletion and modification (MySQL)
LeetCode简单题之统计字符串中的元音子字符串
Idea: export Yapi interface using easyyapi plug-in
青苹果影视系统源码 影视聚合 影视导航 影视点播网站源码
Talk about the basic but not simple stock data
Weekly leetcode - 06 array topics 7 ~ 739 ~ 50 ~ offer 62 ~ 26 ~ 189 ~ 9
excle加水印
作文以记之 ~ 二叉树的后序遍历
信息收集相关知识点及题解
The simple problem of leetcode is to calculate the numerical sum of strings
A simple theme of Typecho with beautiful appearance_ Scarfskin source code download
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
Redis master-slave server problem
一个必看的微信小程序开发指南1-基础知识了解
form表单 post提交 数据量大的问题
Compiler des questions de principe - avec des réponses
Green apple film and television system source code film and television aggregation film and television navigation film and television on demand website source code
mysql查询字符串类型的字段使用数字类型查询时问题