
队列的顺序存储结构
#define MAXSIZE 100
typedef struct
{
ElemType *base;
int front;
int rear;
}cycleQueue;
initQueue(cycleQueue *q)
{
q->base = (ElemType *)malloc(MAXSIZE * sizeof(ElemType));
if( !q->base)
exit(0);
q->front = q->rear = 0;
}
insertQueue(cycleQueue *q, ElemType e)
{
if( (q->rear+1)%MAXSIZE == q->front)
return;
q->base[q->rear]= e;
q->rear = (q->rear+1) % MAXSIZE;
}
deleteQueue(cycleQueue *q, ElemType *e)
{
if( q->front == q->rear)
return;
*e = q->base[q->front];
q->front = (q->front+1) % MAXSIZE;
}
近期评论