/* 线性队列操作 */
#define MAX_QUEUE_SIZE 100
#define TRUE 1
#define FALSE 0
#define IS_QUEUE_EMPTY(front, rear) (front == rear ? TRUE: FALSE)
#define IS_QUEUE_FULL(rear) (rear == MAX_QUEUE_SIZE - 1 ? TRUE: FALSE)
typedef struct info{
int key;
/* other fields */
}element;
element queue[MAX_QUEUE_SIZE];
void addq(int *rear, element item)
{
if(IS_QUEUE_FULL(*rear)){
queue_full();
return ;
}
queue[++*rear] = item;
}
void queue_full(void)
{
printf("Queue is full.\n");
/* other operations */
return ;
}
element deleteq(int *fount, int rear)
{
if(IS_QUEUE_EMPTY(*fount, rear))
return queue_empty(rear);
return queue[++*front];
}
element queue_empty(int rear)
{
/* other operations */
return queue[rear];
}
线性队列操作
最新推荐文章于 2022-09-05 21:59:39 发布