链队的基本操作

来源:互联网 发布:手机微信监控软件 编辑:程序博客网 时间:2024/06/10 16:36

链队的基本操作:

        1,存储结构:

        2,创建链式队列:

        3,队尾插入,队首删除:

         4,遍历操作:

typedef int QElemType;typedef  struct  node{    int data;    struct  node *next;}QNode,*QueuePre;typedef struct{    QueuePre Front;    QueuePre  rear;}LinkQueue;void  CreatQueue(LinkQueue  &Q){    Q.rear=(QueuePre)malloc(sizeof(QNode));    Q.Front=Q.rear;    if(!Q.Front)  exit(-2);    Q.rear->next=NULL;}void EnQueue(LinkQueue  &Q,int e){    QueuePre p;    p=(QueuePre)malloc(sizeof(QNode));    if(!p)  exit(-2);    p->data=e;    p->next=NULL;    Q.rear->next=p;    Q.rear=p;}void DeleQueue(LinkQueue &Q,int &e){    QueuePre p;    if(Q.Front==Q.rear) return ;    p=Q.Front->next;    e=p->data;    Q.Front->next=p->next;    if(Q.rear==p) Q.rear=Q.Front;    free(p);}void  TraverseQueue(LinkQueue &Q){    if(Q.rear==Q.Front) return;    QueuePre  p;    p=Q.Front->next;    while(p)    {        printf("%d ",p->data);        p=p->next;    }}


0 0
原创粉丝点击