004 队列的顺序存储
2017-07-20 14:09
274 查看
队列
队列先进先出,任意一本书上都有详细的介绍,这里不废话了,直接上代码。循环队列-顺序存储方式
#include<iostream> using namespace std; #define MaxSize 20 typedef int elemtype; typedef struct { elemtype data[MaxSize]; int front, rear; }SqQueue; void InitQueue(SqQueue &q) { q.front = q.rear = 0; } bool EmptyQueue(SqQueue &q) { if (q.front == q.rear) { cout << "The Queue is empty" << endl; return true; } else { cout << "Not empty !!" << endl; return false; } } bool EnQueue(SqQueue &q, int x) { if ((q.rear + 1) % MaxSize == q.front) { cout << "The queue is full !!" << endl; return false; } q.data[q.rear] = x; q.rear = (q.rear + 1) % MaxSize; cout << "Adding to the queue successful !" << endl; return true; } bool OutQueue(SqQueue &q) { if (q.front == q.rear) return false; //队列是空的,返回错误 elemtype x; x = q.data[q.front]; q.front = (q.front + 1) % MaxSize; cout << "Outing from the queue successful !" << x << endl; return true; } int main() { SqQueue q; InitQueue(q); EmptyQueue(q); EnQueue(q, 22); EmptyQueue(q); OutQueue(q); EmptyQueue(q); system("pause"); }
相关文章推荐
- 队列的顺序表存储结构
- 采用顺序存储实现循环队列的初始化、入队、出队操作。
- 2.3.1 队列及顺序存储实现
- 从一个队列中取出一个元素再放回去同时保持原来的顺序,不申请非必需的空间存储队列中的元素
- 数据结构-队列的顺序存储(循环队列)
- 队列顺序循环存储实现
- 循环队列--队列的顺序存储表示形式[原创]
- 队列的顺序存储及其基本操作
- 线性表(List)---队列的顺序存储
- 队列(顺序存储)C++模板实现
- 队列顺序存储 - 设计与实现 - API函数
- c++实现顺序存储的队列
- 顺序存储队列实现
- 队列 顺序存储
- 队列-顺序存储-简单实现
- 队列——顺序存储的循环队列(存储元素为自定义类型)
- 队列的顺序存储与链式存储
- 循环队列的顺序存储实现
- 队列的顺序存储及其基本操作
- 队列的顺序存储和实现