数据结构_循环队列
来源:互联网 发布:软件系统结构设计 编辑:程序博客网 时间:2024/05/16 00:42
#include<iostream>
#include<cstdlib>
using namespace std;
const int maxSize = 50;
typedef struct
{
int data[maxSize];
int front;
int rear;
}Queue;
void InitQueue(Queue &Q)//初始化顺序队列
{
Q.front = 0;
Q.rear = 0;
}
int EnQueue(Queue &Q, int e)
{
if((Q.rear +1)%maxSize == Q.front)
return 0;
Q.data[Q.rear] = e;
++Q.rear;
return 1;
}
int DeQueue(Queue &Q, int &e)
{
if(Q.front == Q.rear)
return 0;
e = Q.data[Q.front];
++Q.front;
return 1;
}
int main()
{
const int N = 10;
int temp;
Queue Q;
InitQueue(Q);
for(int i=0;i<N;++i)
{
EnQueue(Q,i+1);
}
while(Q.front != Q.rear)
{
DeQueue(Q,temp);
cout<<temp<<endl;
}
system("pause");
return 0;
}
#include<cstdlib>
using namespace std;
const int maxSize = 50;
typedef struct
{
int data[maxSize];
int front;
int rear;
}Queue;
void InitQueue(Queue &Q)//初始化顺序队列
{
Q.front = 0;
Q.rear = 0;
}
int EnQueue(Queue &Q, int e)
{
if((Q.rear +1)%maxSize == Q.front)
return 0;
Q.data[Q.rear] = e;
++Q.rear;
return 1;
}
int DeQueue(Queue &Q, int &e)
{
if(Q.front == Q.rear)
return 0;
e = Q.data[Q.front];
++Q.front;
return 1;
}
int main()
{
const int N = 10;
int temp;
Queue Q;
InitQueue(Q);
for(int i=0;i<N;++i)
{
EnQueue(Q,i+1);
}
while(Q.front != Q.rear)
{
DeQueue(Q,temp);
cout<<temp<<endl;
}
system("pause");
return 0;
}
0 0
- 数据结构_循环队列
- 数据结构_循环队列
- 【数据结构_队列_Queue_0965】循环队列
- 数据结构的C实现_循环队列
- 数据结构学习之_循环队列
- 数据结构的C实现_循环队列
- 数据结构复习_队列、循环对列
- 数据结构_线性表_顺序队列_循环队列_链队列
- 数据结构_队列-循环队列实现模拟舞伴配对问题
- 数据结构_队列-循环队列实现模拟舞伴配对问题
- 【数据结构】队列-循环队列
- 【数据结构-队列】循环队列
- 数据结构(队列):循环队列
- 数据结构_循环队列相关操作_C语言源代码
- 数据结构基础8_循环队列(顺序实现)
- 队列_静态循环队列
- 数据结构-08 队列(循环队列)
- 数据结构之循环队列
- 【算法导论】堆排序和优先级队列
- linux内核源代码分析
- overloading stream insertion and stream extraction operators
- iOS7的一些总结:使用UIView的一种有效方法
- HDOJ 4864 Task
- 数据结构_循环队列
- 年少无知
- js的四舍五入
- ibatis 中 $与#的区别
- PHP安装环境,服务器不支持curl_exec的解决办法
- 黑马程序员——面向对象7:Main函数
- 法规的合法化法规和规范价格和
- 两个日期相减的时间
- iPhone6分辨率与适配