如果用一个循环数组q[0..m-1]表示队列时,该队列只有一个队列头指针front,不设队列尾指针rear

如果用一个循环数组q[0..m-1]表示队列时,该队列只有一个队列头指针front,不设队列尾指针rear,而改置计数器count用以记录队列中结点的个数.
编写实现队列的基本运算:判空,入队,出队(3分)
队列中能容纳元素的最多个数是多少 (1分)

/* 将data入循环队列 */
void EnQueue(Queue *Q, ElemType data)
{
if((Q->rear+1)%MAX == (Q->rear-Q->count+MAX)%MAX)
return; /* 队列为满,返回 */
Q->base[Q->rear] = data;
Q->rear = (Q->rear+1)%MAX;
Q->count++;
}

/* 出队列,结果存*data中 */
void DeQueue(Queue *Q, ElemType *data)
{
if(Q->rear == (Q->rear-Q->count+MAX)%MAX)
return; /* 队列为空,返回 */
*data = Q->base[(Q->rear-Q->count+MAX)%MAX];
Q->count--;
}

队列中能容纳元素的最多个数是m-1个。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-04-13
The cycle of life and work , more and more irritable and hopeless . Busy with boring a chat all day affairs, seem to have forgotten the cycle of seasons out of the window there .

suddenly discovered , grass green , and blossoms - those no name glamorous flowers.

Another spring has come . Memory have not had time to seriously fall farewell , lawnmowers singing has not completely silent , heart and lung were also awakened flowing aromatic grass , but that ,mac cosmetics, after all, what happened the following year .

peacock walking on the river , wearing edge among the men and women ,Ray Ban sunglasses, there is a hope for submerged .

with his own joy, anger, sadness and return to nest ,Discount Oakley sunglasses, to continue with their own.

nice quiet life ! ! ! !
相似回答