这个队列为什么没有输入,哪错了??
#include <stdio.h>#include <malloc.h>
typedef struct queue
{
int * pbase;
int rear;
int front;
}QUEUE;
void init (QUEUE *);
void en_queue (QUEUE*,int);
void traverse (QUEUE*);
int main(void)
{
QUEUE q;
init (&q);
en_queue (&q,1);
en_queue (&q,2);
en_queue (&q,3);
en_queue (&q,4);
en_queue (&q,5);
en_queue (&q,6);
traverse (&q);
return 0;
}
void init (QUEUE * pq)
{
pq->pbase = (int *)malloc(sizeof(int)*6);
pq->front = 0;
pq->rear = 0;
}
void en_queue (QUEUE* pq,int val)
{
pq->pbase[pq->rear] = val;
pq->rear = (pq->rear+1)%6;
}
void traverse (QUEUE* pq)
{
int i;
i = pq->front;
while (i != pq->rear)
{
printf("%3d",pq->pbase[i]);
i = (i+1)%6;
}
printf("\n");
}