您的位置:首页 > 其它

双端队列部分操作(剩下部分待补)

2012-09-01 22:00 288 查看
/* 双端队列操作 */
#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 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: