数据结构栈和队列之排队叫号系统

  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 }

 

转载于:https://www.cnblogs.com/WuYangdan-5201314/p/10916335.html

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值