/* 双端队列操作 */
#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 && front == 0) ? TRUE: FALSE))
int front = MAX_QUEUE_SIZE / 2, rear = MAX_QUEUE_SIZE / 2;
typedef struct info{
int key;
/* other fields */
}element;
element queue[MAX_QUEUE_SIZE];
void add_double_port_queue(int *front, int *rear, element item)
{
*rear = (*rear + 1) % MAX_QUEUE_SIZE;
if(IS_QUEUE_FULL(front, *rear)){
queue_full(*rear);
return ;
}
if(*rear != MAX_QUEUE_SIZE - 1){
queue[++*rear] = item;
return ;
}
if(*front != 0){
queue[--*front] = item;
return ;
}
}
void queue_full(void)
{
printf("Full.\n");
/* other operations */
return ;
}
双端队列部分操作(剩下部分待补)
最新推荐文章于 2024-01-19 04:10:13 发布