# 队列的顺序存储实现----（附完整代码）

#include<stdio.h>
#include<stdlib.h>
typedef int Position;
typedef int ElementType;
typedef struct QNode * PtrToQNode;
struct QNode{
int * Data;
int Front,Rear;
int MaxSize;
};
typedef PtrToQNode Queue;

//创建队列
Queue CreateQueue(int MaxSize){
Queue Q = (Queue)malloc (sizeof(struct QNode));
Q->Data=(ElementType *)malloc(MaxSize * sizeof(ElementType));
Q->Front=Q->Rear=0;
Q->MaxSize=MaxSize;
return Q;
}

//入队
bool IsFull(Queue Q){
return ((Q->Rear+1) % Q->MaxSize == Q->Front);
}

if(IsFull(Q)){
printf("队列满\n");
}else{
Q->Rear=(Q->Rear+1) % Q->MaxSize;
Q->Data[Q->Rear] = X;
printf("入队成功\n");
}
}

bool IsEmpty(Queue Q){
return (Q->Front==Q->Rear);
}

int Delete(Queue Q){
if(IsEmpty(Q)){
printf("队列空\n");
}else{
Q->Front=(Q->Front+1) % Q->MaxSize;
printf("%d ",Q->Data[Q->Front]);
}
}

int main(){
//初始化
Queue Q = CreateQueue(10);
//入队
int i,n,z,q;
printf("需要入队几个数: ");
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&z);
}
//出队
printf("出队顺序为: \n");
while(!IsEmpty(Q)){
Delete(Q);
}
return 0;
}