#include <iostream.h>
#include <stdlib.h>
#define NULL 0
typedef struct qnode
{
long int data;
struct qnode *next;
}QNode;
typedef struct
{
QNode * front;
QNode * rear;
}LiQueue;
void menu();
void InitQueue(LiQueue *&q);
long int enQueue(LiQueue *q);
void deQueue(LiQueue *&q , long int &e);
void chaxun(LiQueue *q);
int main()
{
LiQueue *q;
long int e = 0;
int n;
InitQueue(q);
do
{
menu();
cout << "\n请输入选项(1 <= n <= 5): ";
while(cin >> n )
{
if(n >= 1 && n <= 5)
break;
else
cout << "您输入不合法请重新输入:";
}
switch(n)
{
case 1:
cout << "\n请输入病历号: ";
e = enQueue(q);
break;
case 2:
deQueue(q,e);
cout <<e << "号病人已就诊!\n";
e = 0;
break;
case 3:
chaxun(q);
break;
case 4:
chaxun(q);
break;
case 5:
cout <<"谢谢您的使用,再见!\n";
break;
}
}while(n != 5);
return 0;
}
void menu()
{
cout << "\n-----**医院就诊系统**------\n\n" ;
cout<<" (1)排队 "<<endl;
cout<<" (2)就诊 "<<endl;
cout<<" (3)查看排队 "<<endl;
cout<<" (4)不再排队,余下依次就诊 "<<endl;
cout<<" (5)下班,退出 "<<endl;
}
void InitQueue(LiQueue *&q)
{
q = (LiQueue *)malloc(sizeof(LiQueue));
q ->front = q->rear = NULL;
}
long int enQueue(LiQueue *q)
{
QNode *p;
long int e;
cout << "\n请输入您的病历号:";
cin >> e;
p = (QNode *)malloc(sizeof(QNode));
p ->data = e;
p ->next = NULL;
if(q ->rear == NULL)
q ->front = q ->rear = p;
else
{
q ->rear ->next = p;
q -> rear = p;
}
return e;
}
void deQueue(LiQueue *&q , long int &e)
{
QNode *t;
if(q -> rear == NULL)
{
cout << "当前没有排队病人哦!\n";
return ;
}
t = q ->front;
if(q -> front == q -> rear)
q -> front = q -> rear = NULL;
else
q ->front = q -> front -> next;
e = t ->data;
free(t);
return ;
}
void chaxun(LiQueue *q)
{
QNode * p;
if(q -> rear == NULL)
cout << "没有病人在排队!" ;
else
{
p = q ->front;
while(p != NULL)
{
cout << p ->data << "\n";
p = p ->next;
}
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-52293.html