```cpp
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
typedef struct student
{
public:
int number;
student *next;
}*LinkQueue,Link;
typedef struct stu
{
public:
LinkQueue fronts;
LinkQueue rear;
}*Qnode,qnode;
void init_Queue(Qnode &L);
void input_queue(Qnode &L,int num);
void pop_queue(Qnode &L,int &x);
void search_queue(Qnode &L);
void finish_queue(Qnode &L);
void menu();
int main()
{
Qnode L;
init_Queue(L);
int m,n,q;
bool key=true;
char ans;
tql:
{
cout<<"请输入你想实现的功能"<<endl;
menu();
cin>>q;
switch(q)
{
case 1:
cout<<"请输入排队号"<<endl;
do
{
cin>>m;
input_queue(L,m);
cout<<"是否继续 Y /y or N /n"<<endl;
setbuf(stdin,NULL);
cin>>ans;
if(ans=='N'||ans=='n')
{
key=false;
}
}while(key);
break;
case 2:
pop_queue(L,n);
break;
case 3:
search_queue(L);
break;
case 4:
finish_queue(L);
break;
default :
cout<<"输入错误"<<endl;
}
system("pause");
system("cls");
goto tql;
}
return 0;
}
void init_Queue(Qnode &L)// 对列初始化
{
L=new qnode;
L->fronts=L->rear=NULL;
}
void input_queue(Qnode &L,int num) //插入数据
{
LinkQueue s=new Link;
if(L->rear==NULL) //如果对列为空
{
s->number=num;
s->next=NULL;
L->rear=L->fronts=s;
}
else if(L->rear==L->fronts)
{
if(num==L->rear->number)
{
cout<<"号码重复了"<<endl;
return ;
}
else
{
s->number=num;
s->next=NULL;
L->rear->next=s;
L->rear=s;
}
}
else
{
int finds=1;
LinkQueue p=L->fronts;
while(p!=NULL)
{
if(p->number==num)
{
finds=0;
}
p=p->next;
}
if(finds==0)
{
cout<<"号码重复了,输入的无效"<<endl;
return ;
}
else
{
s->number=num;
s->next=NULL;
L->rear->next=s;
L->rear=s;
}
}
}
void pop_queue(Qnode &L,int &x) //病人入诊
{
if(L->rear==NULL)
{
cout<<"没有病人排队"<<endl;
return ;
}
else if(L->fronts==L->rear)
{
LinkQueue p=L->fronts;
x=p->number;
delete(p);
L->fronts=L->rear=NULL;
}
else
{
LinkQueue p=L->fronts;
x=p->number;
L->fronts=p->next;
}
cout<<x<<"号病人请进来就诊"<<endl;
return ;
}
void search_queue(Qnode &L)
{
if(L->rear==NULL)
{
cout<<"现在还没有排队的病人呦"<<endl;
return ;
}
else
{
LinkQueue p=L->fronts;
cout<<"正在排队的病人号码分别是"<<endl;
while(p!=NULL)
{
cout<<p->number<<" ";
p=p->next;
}
}
}
void finish_queue(Qnode &L)
{
if(L->fronts==NULL)
{
cout<<"今天要看病的都看完了呦"<<endl;
exit(1);
}
cout<<"剩下这些依次进来找大夫看病"<<endl;
LinkQueue p=L->fronts;
while(p!=NULL)
{
cout<<p->number<<" ";
p=p->next;
}
cout<<endl;
exit(1);
}
void menu()
{
cout<<"1.病人排队"<<endl;
cout<<"2.就诊"<<endl;
cout<<"3.查看排队"<<endl;
cout<<"4.不再排队,依次就诊"<<endl;
}