1 #ifndef LIQUEUE_H_INCLUDED
  2 #define LIQUEUE_H_INCLUDEF
  3 #include<malloc.h>
  4 #endif
  5 #include "head.h"
  6 #include<stdio.h>
  7 #include<iostream>
  8 #define N 100
  9 typedef int ElemType;
 10 typedef struct qnode
 11 {
 12     ElemType data;
 13     struct qnode *next;
 14 }QNode;
 15 typedef struct
 16 {
 17     QNode *front;
 18     QNode *rear;
 19 }LiQueue;
 20 void InitQueue(LiQueue *&q);
 21 void DestroyQueue(LiQueue *&q);
 22 bool QueueEmpty(LiQueue *q);
 23 int QueueLength(LiQueue *q);
 24 void enQueue(LiQueue *&q,Elemtype e);
 25 bool deQueue(LiQueue *&q,ElemType &e);
 26 int main()
 27 {
 28     LiQueue *qu;
 29     ElemType a,no,ne[n],i=0;
 30     InitQueue(qu);
 31     while(1)
 32     {
 33         printf("1.排队\n2.就诊\n3.查看排队\n4.不在排队,余下依次就诊\n5.下班\n");
 34         printf("\n");
 35         printf("请选择:");
 36         scanf("%d",&a);
 37         switch(a)
 38         {
 39             case 1:
 40                 {
 41                     printf(">>输入病例号");
 42                     scanf("%d");
 43                     enQueue(qu,no);
 44                 }
 45             break;
 46             case 2:
 47                 {
 48                     printf(">>病人");
 49                     deQueue(qu,no);
 50                     printf("%d",no);
 51                     printf("就诊");
 52                     printf("\n");
 53                 }
 54             break;
 55             case 3:
 56                 {
 57                     printf(">>排队病人:");
 58                     while(!QueueEmpty(qu))
 59                     {
 60                         deQueue(qu,ne[i]);
 61                         printf("%d",ne[i]);
 62                         i++;
 63                     }
 64                     printf("\n");
 65                 }
 66             break;
 67             case 4:
 68                 {
 69                     printf(">>病人按以下顺序就诊")
 70                     for(int j=0;j<i;j++)
 71                     {
 72                         printf("%d",ne[j]);
 73                     }
 74                     printf("\n");
 75                 }
 76             break;
 77             default:
 78             a=5;
 79             printf("下班");
 80             printf("\n");
 81             return 0;    
 82         }
 83     }
 84 }
 85 void InitQueue(LiQueue *&q)
 86 {
 87     q=(LiQueue *)malloc(sizeof(LiQueue));
 88     q->front=q->rear=NULL;
 89 }
 90 void DestroyQueue(LiQueue *&q)
 91 {
 92     QNode *r,*p=q->front;
 93     if(p!=NULL)
 94     {
 95         r=->next;
 96         while(r!=NULL)
 97         {
 98             free(p);
 99             p=r;
100             r=->next;
101         }
102     }
103     free(p);
104     free(q);
105 }
106 bool QueueEmpty(LiQueue *q)
107 {
108     return q->rear==NULL;
109 }
110 int QueueLength(LiQueue *q)
111 {
112     return q->rear->data;
113 }
114 void enQueue(LiQueue *&q,ElemType e)
115 {
116     QNode *p;
117     p=(QNode *)malloc(sizeof(QNode));
118     p->data=e;
119     p->next=NULL;
120     if(q->rear==NULL)
121     q->rear=q->feont=p;
122     else
123     {
124         q->rear->next=p;
125         q->rear=p;
126     }
127 }
128 bool deQueue(LiQueue *&q,ElemType &e)
129 {
130     QNode *t;
131     t=q->front;
132     if(q->rear==NULL)
133     return false;
134     if(q->rear==q->front)
135     q->rear=q->front=NULL;
136     else
137     {
138         q->front=q->front->next;
139     }
140     e=t->data;
141     free(t);
142     return true;
143 }

 

posted on 2019-05-24 10:00  Anonym_白熊  阅读(1206)  评论(0编辑  收藏  举报