/*Title:用队列模仿病人看病系统
Time:2018-2-4
Author:邹吉祥
School:IMNU
*/
#include<iostream>
#include<stdio.h>
#include<malloc.h>
using namespace std;
typedef struct QNode //结点信息;
{
//int data; //病人编号;
string id;
string name;
struct QNode* next;
}LiQNode;
typedef struct linknode //队列信息;
{
LiQNode* rear;
LiQNode* front;
}LiQueue;
void InitQueue(LiQueue *& q) //初始化队列;
{
q=(LiQueue*)malloc(sizeof(LiQueue));
q->rear=q->front=NULL;
}
void Destroy(LiQueue * & q)
{
LiQNode * t=q->front;
LiQNode * p;
if(t!=NULL)
{
p=t->next;
while(p!=NULL)
{
free(t);
t=p;
p=t->next;
}
free(t);
}
free(q);
}
//void enQueue(LiQueue *& q,int e) //病人排队;
void enQueue(LiQueue *& q,string e1,string e2) //病人排队;
{
LiQNode * t;
t=(LiQNode*)malloc(sizeof(LiQNode));
t->id=e1;
t->name=e2;
t->next=NULL;
if(q->rear==NULL)
{
q->front=q->rear=t;
}
else
{
q->rear->next=t;
q->rear=t;
}
}
//bool deQueue(LiQueue *& q,int & e)
bool deQueue(LiQueue *& q,string & e1,string & e2)
{
LiQNode * t;
if(q->front==NULL)
return false;
else
{
t=q->front;//出队;
e1=t->id;
e2=t->name;
if(q->front==q->rear)
{
q->front=q->rear=NULL;
}
else
{
q->front=q->front->next;
}
free(t);
return true;
}
}
bool isEmpty(LiQueue* q)
{
return (q->front==NULL);
}
int main()
{
LiQueue * q;
string id1,name1;
int find=1;
InitQueue(q); //初始化;
// cout<<"你好"<<endl;
while(find!=0)
{
cout<<"--------------------------------------------------"<<endl;
cout<<"| 上午好,九江银行欢迎你!!! |"<<endl;
cout<<"| 排队请输入-1 |"<<endl;
cout<<"| 叫号请输入-2 |"<<endl;
cout<<"| 查看排队情况请输入-3 |"<<endl;
cout<<"| 退出请输入-4 |"<<endl;
cout<<"--------------------------------------------------"<<endl;
cout<<"请输入您的选择:";
int com;
scanf("%d",&com); //输入指令;
string e1,e2;
switch(com)
{
case 1: //排队
printf("请输入您的身份证号和姓名;\n");
//int no;
//scanf("%d",&no);
cin>>id1;
cin>>name1;
enQueue(q,id1,name1); //病人编号入队;
break;
case 2: //看病
deQueue(q,e1,e2);
//printf("请%d号病人看病\n",e);
cout<<"请身份证号为:"<<e1<<","<<"姓名为:"<<e2<<",前来办理业务"<<endl;
break;
case 3: //看排队情况;
printf("显示正在排队的情况:\n");
while(!isEmpty(q))
{
deQueue(q,e1,e2);
//printf("%d\n",e);
cout<<e1<<" || "<<e2<<endl;
}
break;
case 4:
find=0;
break;
//default:
//break;
}
}
Destroy(q);
printf("谢谢您的使用\n");
}
用队列模仿病人看病系统
最新推荐文章于 2023-04-06 09:08:14 发布