c语言数据结构循环队列问题
#include<stdio.h>#include<stdlib.h>#definemaxsize12typedefstructNode{intdata[maxsize]...
#include<stdio.h>
#include<stdlib.h>
#define maxsize 12
typedef struct Node
{
int data[maxsize];
int front;
int rear;
}CircQueue;
CircQueue *InitQueue(){
CircQueue *q;
q->front = 0;
q->rear = 0;
return q;
}
CircQueue *EnQueue(CircQueue *q){
int i;
int x;
printf("请输入队列元素:\n");
for(i = 0;i < 3;i++){
if((q->rear+1)%maxsize==q->front){
printf("队满!!!");
}else{
scanf("%d",&x);
q->rear = (q->rear+1)%maxsize;
q->data[q->rear] = x;
}
}
return q;
}
void PrintQueue(CircQueue *q){
while(q->front!=q->rear){
q->front = (q->front+1)%maxsize;
printf("%d ",q->data[q->front]);
}
}
main(){
CircQueue *q;
q = InitQueue();
q = EnQueue(q);
PrintQueue(q);
return 0;
}
编译没有问题,输出有点问题・_・? 展开
#include<stdlib.h>
#define maxsize 12
typedef struct Node
{
int data[maxsize];
int front;
int rear;
}CircQueue;
CircQueue *InitQueue(){
CircQueue *q;
q->front = 0;
q->rear = 0;
return q;
}
CircQueue *EnQueue(CircQueue *q){
int i;
int x;
printf("请输入队列元素:\n");
for(i = 0;i < 3;i++){
if((q->rear+1)%maxsize==q->front){
printf("队满!!!");
}else{
scanf("%d",&x);
q->rear = (q->rear+1)%maxsize;
q->data[q->rear] = x;
}
}
return q;
}
void PrintQueue(CircQueue *q){
while(q->front!=q->rear){
q->front = (q->front+1)%maxsize;
printf("%d ",q->data[q->front]);
}
}
main(){
CircQueue *q;
q = InitQueue();
q = EnQueue(q);
PrintQueue(q);
return 0;
}
编译没有问题,输出有点问题・_・? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询