1、定义
#define QUEUE_DEFAULT_SIZE 8
typedef struct SeqQueue
{
ElemType *base;
int capacity;
int front;
int rear;
}SeqQueue;
2、初始化
void SeqQueueInit(SeqQueue* psq)
{
assert(psq != NULL);
psq->capacity = QUEUE_DEFAULT_SIZE;
psq->base = (ElemType*)malloc(sizeof(ElemType)*psq->capacity);
psq->front = psq->rear = 0;
}
3、判空
bool SeqQueueEmpty(SeqQueue *psq)
{
assert(psq != NULL);
return psq->front == psq->rear;
}
4、入队、出队
void SeqQueueEn(SeqQueue* psq, ElemType x)
{
assert(psq != NULL);
if (psq->rear >= psq->capacity)
{
printf("队列已满,%d不能入队!\n");
return;
}
psq->base[psq->rear++] = x;
}
void SeqQueueDe(SeqQueue* psq)
{
assert(psq != NULL);
if (SeqQueueEmpty(psq))
{
printf("队列已空,不能出队!\n");
return;
}
psq->front++;
}
</