struct Queue *next; }Queue;
//头指针和尾指针 typedef struct {
Queue *front; Queue *rear; }LinkQueue; //初始化队列
status InitQueue(LinkQueue *q) {
q->front=q->rear =NULL; //----无头结点 return OK; }
/*判断队列是否为空*/
status QueueEmpty(LinkQueue *Q) {
return (Q->front==NULL)&&(Q->rear==NULL); /*实际上只须判断队头指针是否为空即可*/ }
//入队
void EnQueue(LinkQueue *q,QElemType e) {
Queue *p;
p=(Queue *)malloc(sizeof(Queue));/*申请新结点*/ p->data=e; p->next=NULL;
if(QueueEmpty(q))
q->front=q->rear=p; else {
/*x插入非空队列的尾*/
q->rear->next=p; /*p链到原队尾结点后*/ q->rear=p;/*队尾指针指向新的尾*/ } }
//出队
QElemType DeQueue(LinkQueue *q) {
Queue *p; QElemType e;
if(QueueEmpty(q)) {
printf("Queue underflow\n");/*下溢*/
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库建立二叉树,并对树进行操作数据结构课程设(14)在线全文阅读。
相关推荐: