顺序队列--简单操作
来源:互联网 发布:java中π怎么表示 编辑:程序博客网 时间:2024/06/03 18:43
实现顺序队列的入队和出队操作
#include<iostream>using namespace std;#define MAX 10class Cirstack{public:Cirstack(){front=rear=MAX-1;} ~Cirstack(){} void EnQueue(int x); int DeQueue(); int GetQueue(); int Empty(){ if(front==rear)return 1;return 0; }private:int data[MAX];int front, rear;};void Cirstack::EnQueue(int x){ //入队if((rear+1)%MAX==front) throw "上溢";rear=(rear+1)%MAX;data[rear]=x;}int Cirstack::DeQueue(){ //出队if(rear==front) throw "下溢";front=(front+1)%MAX;return data[front];}int Cirstack::GetQueue(){int i;if(rear==front) throw "下溢";i=(front+1)%MAX;return data[i];}int main(){Cirstack Que;int a[20],n,i,x;cout<<"How many number do you want?"<<endl;cin>>n;cout<<"请依次输入入队的值:";for(i=0;i<n;i++){cin>>x;Que.EnQueue(x);}cout<<"队头为:"<<Que.GetQueue<<endl;cout<<"出栈顺序为:"<<endl;for(i=0;i<n;i++)cout<<Que.DeQueue()<<" ";cout<<endl;return 0;}
实验结果:
阅读全文
0 0
- 顺序队列--简单操作
- 简单顺序队列操作(不考虑循环)
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列基本操作
- 顺序队列 操作
- 顺序队列一些操作
- 顺序队列的操作
- css中overflow滑动效果在IOS中不流畅
- BigDecimal20171012 java.lang.NumberFormatException
- Tomcat用作文件下载服务器
- 【vue系列之二】详解vue-cli 2.0配置文件
- python笔记: 类中的__str__ 函数
- 顺序队列--简单操作
- PHP-Iterator迭代器(遍历)接口详讲
- ssh整合配置文件
- Oracle查询视图需要有基表的查询权限吗?
- cornerstone 锁死与解锁 An error occurred and the operation could not be completed.
- Javascript中BOM与DOM
- 详解YUV数据格式
- 事务引发的tomcat重启
- ANSI Common Lisp译本笔记9