《队列操简单作》由会员分享,可在线阅读,更多相关《队列操简单作(1页珍藏版)》请在金锄头文库上搜索。
下面给出循环队列的运算算法:(1)将循环队列置为空/将队列初始化SeQueue:SeQueue() front=0;rear=0;coutinit!endl;(2)判断循环队列是否为空int SeQueue:Empty() if(rear=front) return(1);else return(0);(3)在循环队列中插入新的元素xvoid SeQueue:AddQ(ElemType x) if(rear+1) % MAXSIZE=front) cout QUEUE IS FULL! endl;else rear=(rear+1) % MAXSIZE;elemrear=x;cout OK!;(4)删除队列中队首元素ElemType SeQueue:DelQ() if(front=rear) cout QUEUE IS EMPTY! endl; return -1;else front=(front+1) % MAXSIZE;return(elemfront);(5)取队列中的队首元素ElemType SeQueue:Front() ElemType x;if(front= rear)coutQUEUE IS EMPTY endl;else x= elem(front+1)%MAXSIZE;return (x);