原理:

  • 通过单链表实现的队列,队列就是一个尾插头删的单链表,先实现一个链表 ,再实现一个队列包括队头指针和队尾指针
  • C语言实现队列
 1 #ifndef Queue_h
 2 #define Queue_h
 3 
 4 #include <stdio.h>
 5 
 6 typedef int QDataType;        //数据类型
 7 
 8 typedef struct ListNode        //通过链表实现的
 9 {
10     QDataType _data;
11     struct ListNode* _pNext;
12 }ListNode,*pListNode;
13 
14 typedef struct Queue
15 {
16     pListNode _pHead;        //头指针
17     pListNode _pTail;        //尾指针
18 }Queue;
19 
20 void QueueInit(Queue* q);        //初始化
21 void QueuePush(Queue* q, QDataType d);//进队列(尾插)
22 void QueuePop(Queue* q);        //出队列(头删)
23 int QueueSize(Queue* q);        //求队列大小
24 int QueueEmpty(Queue* q);        //队列判空
25 QDataType Front(Queue* q);        //获取队头元素
26 QDataType Back(Queue* q);        //获取队尾元素
27 
28 #endif /* Queue_h */
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-27
  • 2022-12-23
猜你喜欢
  • 2021-12-24
  • 2021-05-17
  • 2022-12-23
  • 2021-12-16
  • 2019-02-27
相关资源
相似解决方案