下载此文档

循环队列.docx


文档分类:IT计算机 | 页数:约5页 举报非法文档有奖
1/5
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/5 下载此文档
文档列表 文档介绍
C++源代码文辑
代码名称:循环队列的创建、进出队列
编程工具: Microsoft Visual C++
作 者: 长风夜雨
说明:
将以下原代码直接复制至Microsoft Visual C++,测试已通过。
#include<>
#include<>
#include<>
#define QueueElementType int
#define MAXSIZE 50
typedef struct
{
QueueElementType element[MAXSIZE];
int front;
int rear;
}SeqQueue;
//初始化队列
void InitQueue(SeqQueue *Q)
{
Q->front=Q->rear=0;
}
//遍历队列
void ShowQueue(SeqQueue *Q)
{
if(Q->front==Q->rear)
cout<<"队列为空!"<<endl;
else
{
cout<<"您的队列如下:"<<endl<<endl;
cout<<"————————————————————————————————"<<endl;
for(int i=Q->front ; i<Q->rear ; i++)
cout<<Q->element[i]<<endl;
cout<<"————————————————————————————————"<<endl<<endl;
}
}
//进队
void EnterQueue(SeqQueue *Q , QueueElementType x)
{
if((Q->rear+1)%MAXSIZE==Q->front)
cout<<"队列已满!"<<endl;
else
{
Q->element[Q->rear]=x;
Q->rear=(Q->rear+1)%MAXSIZE;
}
}
//退出队列
void DeleteQueue(SeqQueue *Q)
{
if(Q->front==Q->rear)
cout<<"队列为空!"<<endl;
else
{
Q->front=(Q->front+1)%MAXSIZE;
cout<<"出对成功!"<<endl;
}
}
void main()
{
//初始化队列
SeqQueue *Q;
Q=(SeqQueue *)malloc(sizeof(SeqQueue));
InitQueue(Q);

//创建队列
int i;
cout<<"请输入队列长度:"<<endl;
cin>>i;
cout<<"请依次输入队列元素:"<<endl;
for(int j=0 ; j<i ; j++)
{
int x;
cin>>x;
EnterQueue(Q,x)

循环队列 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数5
  • 收藏数0 收藏
  • 顶次数0
  • 上传人wxc6688
  • 文件大小19 KB
  • 时间2021-01-09
最近更新