程序能够运行出来,就是在给队列输入x值的时候不能够输进去,求解!
#include<stdio.h>
#define maxSize 8
typedef int QElemType;
typedef struct {
QElemType elem[maxSize];
int front,rear;
}CircQueue;
//初始化
void InitQueue (CircQueue &s){
s.front=s.rear=0;
}
//进队列
int EnQueue (CircQueue &s, QElemType x){
if((s.rear+1)%maxSize==s.front) return 0;//队满
s.elem[s.rear]=x;
s.rear=(s.rear+1)%maxSize;
return 1;
};
//出队列
int DeQueue (CircQueue &s, QElemType &x){
if(s.front==s.rear) return 0;//对空
x=s.elem[s.front];
s.front=(s.front+1)%maxSize;
return 1;
};
int GetFront (CircQueue &s, QElemType &x){
if(s.rear==s.front) return 0;
x=s.elem[s.front];
return 1;
};
//判断空
int QueueEmpty(CircQueue &s){
return s.front=s.rear;
};
//判断满
int QueueFull(CircQueue &s){
return (s.rear+1)%maxSize==s.front;
};
//队列元素数
int QueueSize(CircQueue &s){
return (s.rear-s.front+maxSize)%maxSize;
};
int main(){
CircQueue s;
int i,x;
EnQueue(s,x);
for(int i=0;i<maxSize;i++){
printf("请输入x:");
scanf("%d",x);
}
DeQueue(s,x);
QueueSize(s);
}
原文地址:https://www.cnblogs.com/lvzhiqi/p/10793612.html