帮忙程序找下错误
//说明:这是一个队列的应用,出了些我搞不清楚的问题,请高手帮忙看看,最好是帮忙运行运行 #include<stdio.h>
#include<stdlib.h>
#include<time.h>
struct QueueRecord;
typedef struct QueueRecord * Queue;
int IsEmpty( Queue Q );
int IsFull( Queue Q );
static int Succ( int Value, Queue Q );
void Enqueue( char x, Queue Q );
void Dequeue( Queue Q );
Queue InitQueue();
void print ( Queue Q );
#define MAX_SIZE 20;
struct QueueRecord
{
int Capacity;
int Front;
int Rear;
int Size;
char *Array;
};
int IsEmpty( Queue Q )
{
return Q->Size == 0;
}
int IsFull( Queue Q )
{
return Q->Size == Q->Capacity;
}
static int Succ( int Value, Queue Q )
{
if ( ++Value == Q->Capacity )
Value = 0;
return Value;
}
void Enqueue( char x, Queue Q )
{
if ( IsFull( Q ) )
printf("Full queue!");
else
{
Q->Size++;
Q->Rear = Succ( Q->Rear, Q );
Q->Array[ Q->Rear ] = x;
}
}
void Dequeue( Queue Q )
{
if ( IsEmpty( Q ) )
{
printf("Empty Queue!");
exit(-1);
}
Q->Size--;
Q->Front = Succ( Q->Front, Q );
}
Queue InitQueue( void ) //这里我是想创建一个队列的,但是感觉有问题,又不知道出什么错
{
Queue Q;
Q->Array = (char * ) calloc (20, sizeof( char ));
if ( Q->Array == NULL )
exit(-1);
Q->Capacity = MAX_SIZE;
Q->Front = 1;
Q->Rear = 0;
Q->Size = 0;
return Q;
}
void print ( Queue Q )
{
int i, j;
i = Q->Front;
for ( j = 0; j <= Q->Size; j++)
{
printf("%c ", Q->Array[i]);
if( ++i > Q->Capacity )
i = 0;
}
}
main()
{
int random_i, i;
char x;
Queue Q;
Q = InitQueue();
randomize();
random_i = random( 20 );
for ( i = 0; i < random_i; i++) //运行的时候循环好像有问题,现在自己都迷糊了
{
printf("Input Element:");
scanf("%c", &x);
Enqueue( x, Q );
}
print( Q );
randomize();
random_i = random( 20 );
for ( i = 0; i < random_i; i++ )
Dequeue( Q );
print( Q );
}