链式队列操作

来源:互联网 发布:在哪买淘宝号安全 编辑:程序博客网 时间:2024/05/16 15:02
#include<stdio.h>#include<stdlib.h>/*链队列的结点定义*/typedef struct node{    int data;    struct node *next;}Qnode;/*队列链式结构定义*/typedef struct LinkQueue{Qnode *front, *rear;} LQueue; /*入队操作*/void En_LQueue(LQueue *HQ, int x){Qnode *p = (Qnode *)malloc(sizeof(Qnode)); //新生成的结点p->data = x;p->next = NULL;if(NULL == HQ->rear){HQ->front = HQ->rear = p;}else{HQ->rear->next = p;HQ->rear = p;}}/*出队操作*/void De_LQueue(LQueue *HQ){Qnode *p;int x;if(HQ->front == NULL){printf("队列为空");return ;}else{p = HQ->front;    //取出对头给px = p->data;      //对头数据元素存入xHQ->front = p->next;  //对头指向下一个元素if(NULL == HQ->front)  //队列为空时,队尾也置空{    HQ->rear = NULL;}free(p);printf("出队列的元素是:%d",x);}}

 
原创粉丝点击