主题:[讨论]大家进来看看一个顺序列的输出问题
我想知道最后那个prin函数输出为什么不能没有 % MAXSIZE ?那个的意义在哪?如果不要输出的是什么值?
#include<stdio.h>
#define MAXSIZE 50
typedef int datatype;
typedef struct
{
datatype data[MAXSIZE];
int front,rear;
}sequeue;
int main()
{
int choice;
sequeue s,*sq = &s;
void setnull(sequeue *);
void creat(sequeue *);
void prin(sequeue *);
/* void enqueue(sequeue *);
void dequeue(sequeue *);
int Front(sequeue *);
int empty(sequeue *); */
setnull(sq);
creat(sq);
prin(sq);
printf("输入操作选择:5.置空 1.入队 2.出队 3.取对头元素 4.判对空 0.退出");
scanf("%d",&choice);
while(choice != 0)
{
switch(choice)
{
case 5:setnull(sq);
/* case 1:enqueue(sq);
print(sq);
break;
case 2:dequeue(sq);
print(sq);
break;
case 3:printf("对头元素是:%d ",Front(sq));
break;
case 4:if(empty(sq))
printf("空队");
else
printf("非空队");
break; */
}
printf("输入操作选择: 5.置空 1.入队 2.出队 3.取对头元素 4.判对空 0.退出");
scanf("%d",&choice);
}
return 0;
}
void setnull(sequeue *sq)
{
sq->front = MAXSIZE - 1;
sq->rear = MAXSIZE - 1;
}
void creat(sequeue *sq)
{
int num;
printf("输入要入队的元素,以0结束");
scanf("%d",&num);
while(num != 0)
{
if(sq->front == (sq->rear + 1) % MAXSIZE)
printf("队满上溢");
else
{
sq->rear = (sq->rear + 1) % MAXSIZE;
sq->data[sq->rear] = num;
}
scanf("%d",&num);
}
}
void prin(sequeue *sq)
{
while((sq->front) % MAXSIZE != (sq->rear) % MAXSIZE)
{
printf("%d",sq->data[++sq->front % MAXSIZE]);
}
}