当前位置:网站首页>队列(C语言)
队列(C语言)
2022-06-11 22:55:00 【小白丷】
typedef int QDataType;
typedef struct QueueNode
{
struct QueueNode* next;
QDataType data;
}QNode;
typedef struct Queue
{
//int size;
QNode* head;
QNode* tail;
}Queue;
void QueueInit(Queue* pq)
{
assert(pq);
pq->head = pq->tail = NULL;
}
void QueueDestroy(Queue* pq)
{
QNode* cur = pq->head;
while (cur)
{
QNode* next = cur->next;
free(cur);
cur = next;
}
pq->head = pq->tail = NULL;
}
void QueuePush(Queue* pq, QDataType x)
{
QNode* newnode = (QNode*)malloc(sizeof(QNode));
newnode->data = x;
newnode->next = NULL;
if (pq->tail == NULL)
{
pq->head = pq->tail = newnode;
}
else
{
pq->tail->next = newnode;
pq->tail = newnode;
}
}
void QueuePop(Queue* pq)
{
QNode* del = pq->head;
pq->head = pq->head->next;
free(del);
if (pq->head == NULL)
{
pq ->tail = NULL;
}
}
QDataType QueueFront(Queue* pq)
{
return pq->head->data;
}
QDataType QueueBack(Queue* pq)
{
return pq->tail->data;
}
bool QueueEmpty(Queue* pq)
{
return pq->tail == NULL;
}
int QueueSize(Queue* pq)
{
QNode* cur = pq->head;
int size = 0;
while (cur)
{
size++;
cur = cur->next;
}
return size;
}
边栏推荐
- The key to the safe was inserted into the door, and the college students stole the mobile phone numbers of 1.1 billion users of Taobao alone
- 0-1 knapsack problem of dynamic programming (detailed explanation + analysis + original code)
- Matlab point cloud processing (XXIV): point cloud median filtering (pcmedian)
- Games-101 Yan Lingqi 5-6 lecture on raster processing (notes sorting)
- C# List. Can foreach temporarily / at any time terminate a loop?
- 学1个月爬虫就月赚6000?别被骗了,老师傅告诉你爬虫的真实情况
- SDNU_ ACM_ ICPC_ 2022_ Weekly_ Practice_ 1st (supplementary question)
- Exercise 8-8 judging palindrome string (20 points)
- Message queue MySQL table that stores message data
- Fastapi 5 - common requests and use of postman and curl (parameters, x-www-form-urlencoded, raw)
猜你喜欢

Is it too troublesome to turn pages manually when you encounter a form? I'll teach you to write a script that shows all the data on one page
![[Day8 literature extensive reading] space and time in the child's mind: evidence for a cross dimensional symmetry](/img/c2/e70e7c32c5dc5554dea29cb4627644.png)
[Day8 literature extensive reading] space and time in the child's mind: evidence for a cross dimensional symmetry

Inventory | more than 20 typical security incidents occurred in February, with a loss of nearly $400million

How to do investment analysis in the real estate industry? This article tells you

NLP - fastText

Pourquoi Google Search ne peut - il pas Pager indéfiniment?

Bit operation in leetcode

The second bullet of in-depth dialogue with the container service ack distribution: how to build a hybrid cloud unified network plane with the help of hybridnet

Leetcode must review 20 lintcode (5466421166978227)

Lekao.com: what is the difference between Level 3 health managers and level 2 health managers?
随机推荐
Dynamics 365 选项集操作
Exercise 6-2 using functions to sum a special series of a numbers (20 points)
习题8-2 在数组中查找指定元素 (15 分)
Lecture de l'article dense Visual SLAM for RGB - D Cameras
【自然语言处理】【多模态】ALBEF:基于动量蒸馏的视觉语言表示学习
2022年高处安装、维护、拆除操作证考试题库模拟考试平台操作
[Day8 literature extensive reading] space and time in the child's mind: evidence for a cross dimensional symmetry
华为设备配置HoVPN
Huawei cloud, OBS
习题11-2 查找星期 (15 分)
Google搜索为什么不能无限分页?
Deconstruction of volatile | community essay solicitation
[technology sharing] after 16 years, how to successfully implement the dual active traffic architecture of zhubajie.com
习题9-5 通讯录排序 (20 分)
0-1 knapsack problem of dynamic programming (detailed explanation + analysis + original code)
Exercise 11-3 calculate the longest string length (15 points)
直播预告|FeatureStore Meetup V3 重磅来袭!
习题8-5 使用函数实现字符串部分复制 (20 分)
Start notes under the Astro Pro binocular camera ROS
Cloudcompare source code analysis: read ply file