📄 queue.cpp
字号:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <math.h>
#include <process.h>
#define OK 1
#define ERROR 0
typedef int Status;
typedef int QElemType;
#define MAXQSIZE 10000
struct SqQueue
{
QElemType *base;
int frount;
int rear;
};
Status InitQueue(SqQueue &Q)
{
Q.base=(QElemType *)malloc(MAXQSIZE*sizeof(QElemType));
Q.frount=Q.rear=0;
return OK;
}
Status EnQueue(SqQueue &Q,QElemType e)
{
if((Q.rear+1)%MAXQSIZE==Q.frount) return ERROR;
Q.base[Q.rear]=e;
Q.rear=(Q.rear+1)%MAXQSIZE;
return OK;
}
int QueueTraverse(SqQueue Q)
{
int i;
i=Q.frount;
if((Q.rear+1)%MAXQSIZE==Q.frount) return ERROR;
while(i!=Q.rear)
{
printf("%d ",(*(Q.base+i)));
i=(i+1)%MAXQSIZE;
}
printf("\n");
return OK;
}
int main()
{
int i=0;
QElemType d;
SqQueue Q;
InitQueue(Q);
do
{
scanf("%d",&d);
if(d==-1) break;
i++;
EnQueue(Q,d);
}while(i<MAXQSIZE-1);
QueueTraverse(Q);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -