数据结构学习笔记(5)---静态与动态队列
来源:互联网 发布:最好的电路仿真软件 编辑:程序博客网 时间:2024/05/16 05:02
(一)静态队列
数据结构:
typedef struct Node{ int date; struct Node *next;}Node, *PNode;typedef struct queue{ PNode top; PNode bottom;}Queue, *PQueue;
(1)初始化
void InitQueue(Queue *queue){ queue->top = 0; queue->bottom = 0;}
(2)入栈
void Push(Queue *queue, int date){ if ((queue->top + 1) % MAXSIZE == queue->bottom) { cout << "队列已满!" << endl; return; } queue->elem[queue->top] = date; queue->top = (queue->top +1)% MAXSIZE;}
(2)出栈
void Pop(Queue * queue, int *date){ if (queue->top == queue->bottom) { cout << "队列为空!" << endl; return; } (*date) = queue->elem[queue->bottom]; queue->bottom = (queue->bottom + 1) % MAXSIZE;}
(二)动态队列
(1)初始化
void InitQueue(PQueue pHead){ pHead->top = NULL; pHead->bottom = NULL;}
(2)入栈
void Push(PQueue pQueue,int date){ PNode pNew= new Node; if (!pNew) { cout << "进队失败!" << endl; return; } pNew->date = date; pNew->next = NULL; if ( IsEmpty(pQueue)) { pQueue->top = pQueue->bottom = pNew; } else { pQueue->top->next = pNew; pQueue->top = pNew; }}
(3)出栈
void Pop(PQueue pQueue, int *date){ if (IsEmpty(pQueue)) { cout << "出队失败,队列为空!" << endl; return; } if (pQueue->bottom == pQueue->top) { PNode p = pQueue->bottom; (*date) = pQueue->bottom->date; pQueue->bottom = pQueue->top = NULL; delete p; } else { (*date) = pQueue->bottom->date; PNode p = pQueue->bottom; pQueue->bottom = pQueue->bottom->next; delete p; }}
(4)判栈空
bool IsEmpty(PQueue pQueue){ return pQueue->top == NULL&&pQueue->bottom == NULL;}
阅读全文
0 0
- 数据结构学习笔记(5)---静态与动态队列
- 数据结构学习笔记(4)---静态与动态栈
- 数据结构学习笔记 --- 队列(链队列)
- 数据结构学习笔记 --- 队列(链队列)
- 学习笔记:数据结构(二)栈与队列
- 【学习笔记----数据结构05-栈与队列】
- 数据结构学习笔记(8.循环队列与链队列)
- 数据结构学习笔记--队列
- 数据结构学习笔记--队列
- 数据结构学习笔记--队列
- Java学习笔记:反射与代理机制(静态、动态)
- 数据结构学习笔记 --- 栈、队列 (习题)
- 学习笔记--数据结构(之二)队列
- 数据结构学习笔记6(队列)
- 数据结构学习笔记 --- 栈、队列 (习题)
- 严蔚敏版数据结构学习笔记(4):队列
- 数据结构笔记(3)栈与队列
- 数据结构与算法学习笔记:栈与队列
- angularJS指令和表达式
- Caffe学习(9)——计算图片数据的均值
- 【翻译】VTK 8.0.1 发布
- CCF 201512-3 画图
- 九度[1120]-全排列
- 数据结构学习笔记(5)---静态与动态队列
- Scrapy创建爬虫项目步骤
- Android中的多进程与多线程通讯
- 剑指offer--(6) 旋转数组中的最小元素
- 从输入url到页面展示到底发生了什么
- ImportError: No module named examples.tutorials.mnist
- android 圆形头型 bitmap toRoundBitmap
- 计蒜客-汽水瓶
- EasyNVR RTSP转RTMP/HLS流媒体服务器前端构建之:内部搜索功能的实现