/*
某银行营业厅共有6个营业窗口,设有排队系统广播叫号,该银行的业务分为公积金、银行卡、理财卡等三种。公积金业务指定1号窗口,银行卡业务指定2、3、4号窗口,理财卡业务指定5、6号窗口。但如果5、6号窗口全忙,而2、3、4号窗口有空闲时,理财卡业务也可以在空闲的2、3、4号窗口之一办理。
客户领号、业务完成可以作为输入信息,要求可以随时显示6个营业窗口的状态。 */
1.源程序
#include
#include
#define MAXSIZE 10;
typedef struct Peo{
struct Peo *next;
}PeoNode;
typedef struct{
PeoNode *head;
PeoNode *rear;
int length;
}LQueueBank;
LQueueBank InitQueue(LQueueBank *W){
W->length = 0;
W->head = (PeoNode *)malloc(sizeof(PeoNode));
if(W->head!=NULL)
{
W->head->next=NULL;
W->rear=W->head;
}
return *W;
}
void InLCK(LQueueBank *A, LQueueBank *B,LQueueBank *C){
if(B->length
B->length++;
printf("办理中\n");
}
else if(C->length
C->length++;
printf("办理中\n");
}
else{
printf("请等待\n");
A->length++;
A->rear = A->rear->next;
}
}
void InGJJ(LQueueBank *A, LQueueBank *B){
if(B->length
B->length++;
printf("办理中\n");
}
else{
printf("请等待\n");
A->length++;
A->rear = A->rear->next;
}
}
void InYHK(LQueueBank *A, LQueueBank *B){
if(B->length
B->length++;
printf("办理中\n");
}
else{
printf("请等待\n");
A->length++;
A->rear = A->rear->next;
}
}
void Leave(LQueueBank *A, LQueueBank *B,LQueueBank *C,LQueueBank *D,LQueueBank *E,LQueueBank *F){
printf("请输入离开用户所在窗口\n");
int yw;
scanf("%d",&yw);
switch(yw){
case 1:
{
A->rear = A->head;A->length--;
if(D->length > 0) {
printf("请等待办理公积金的第一位用户来窗口1办理\n");
InGJJ(D,A);
}
break;
}
case 2:case 3:case 4:
{
B->rear = B->head->next->next;B->length--;
if(E->length > 0){
printf("请等待办理银行卡的第一位用户来窗口%d办理\n",yw); InYHK(E,B);
}
else if (F->length > 0) {
printf("请等待办理理财卡的第一位用户来窗口%d办理\n",yw); InLCK(F,C,B);
}
break;
}
case 5: case 6:
{
C->length--; C->rear = C->head->next;
if(F->length > 0) InLCK(F,C,B);
printf("请等待办理理财卡的第一位用户来窗口%d办理\n",yw);
break;
}
default: printf("输入有误,请重试!\n");
}
}
void PRINT(LQueueBank *A, LQueueBank *B,LQueueBank *C){
if(A->length == 0) printf("1号窗口空闲中\n");
else printf("1号窗口忙碌中\n");
if(B->length == 0) printf("2号窗口空闲中\n3号窗口空闲中\n4号窗口空闲中\n"); else if(B->length == 1) printf("2号窗口忙碌中\n3号窗口空闲中\n4号窗口空闲中\n"); else if(B->length == 2) printf("2号窗口忙碌中\n3号窗口忙碌中\n4号窗口空闲中\n"); else if(B->length == 3) printf("2号窗口忙碌中\n3号窗口忙碌中\n4号窗口忙碌中\n");
if(C->length == 0) printf("5号窗口空闲中\n6号窗口空闲中\n");
else if(C->length == 1) printf("5号窗口忙碌中\n6号窗口空闲中\n");
else if(C->length == 2) printf("5号窗口忙碌中\n6号窗口忙碌中\n");
}
void main()
{
LQueueBank Wait1,Wait2,Wait3,Busy1,Busy2,Busy3; //1:公积金 2:银行卡 3:理财卡 Wait1 = InitQueue(&Wait1);
Wait2 = InitQueue(&Wait2);
Wait3 = InitQueue(&Wait3);
Busy1 = InitQueue(&Busy1);
Busy2 = InitQueue(&Busy2);
Busy3 = InitQueue(&Busy3);
int ch = 0;
while(1)
{
printf("----------------------------------\n");
printf("1. 办理业务 ");
printf("2. 完成离开 ");
printf("3. 退出 ");
printf("0. 打印当前窗口状态\n");
while(1)
{
scanf("%d",&ch);
if(ch>=0&&ch
else
printf("\n输入有误,请重试!");
}
switch(ch)
{
case 0:{PRINT(&Busy1,&Busy2,&Busy3);break;}
case 1:{
printf("请输入业务种类1/2/3\n");
printf("1. 公积金 2. 银行卡 3. 理财卡\n");
int yw1;
scanf("%d",&yw1);
switch(yw1){
case 1: {InGJJ(&Wait1,&Busy1);break;}
case 2: {InYHK(&Wait2,&Busy2);break;}
case 3: {InLCK(&Wait3,&Busy3,&Busy2);break;}
default: printf("输入有误,请重试!\n");
}
break;
}
case 2:{
Leave(&Busy1,&Busy2,&Busy3,&Wait1,&Wait2,&Wait3);
break;
}
case 3:exit(0); default: break; }
}
}
2.运行窗口截图:
/*
某银行营业厅共有6个营业窗口,设有排队系统广播叫号,该银行的业务分为公积金、银行卡、理财卡等三种。公积金业务指定1号窗口,银行卡业务指定2、3、4号窗口,理财卡业务指定5、6号窗口。但如果5、6号窗口全忙,而2、3、4号窗口有空闲时,理财卡业务也可以在空闲的2、3、4号窗口之一办理。
客户领号、业务完成可以作为输入信息,要求可以随时显示6个营业窗口的状态。 */
1.源程序
#include
#include
#define MAXSIZE 10;
typedef struct Peo{
struct Peo *next;
}PeoNode;
typedef struct{
PeoNode *head;
PeoNode *rear;
int length;
}LQueueBank;
LQueueBank InitQueue(LQueueBank *W){
W->length = 0;
W->head = (PeoNode *)malloc(sizeof(PeoNode));
if(W->head!=NULL)
{
W->head->next=NULL;
W->rear=W->head;
}
return *W;
}
void InLCK(LQueueBank *A, LQueueBank *B,LQueueBank *C){
if(B->length
B->length++;
printf("办理中\n");
}
else if(C->length
C->length++;
printf("办理中\n");
}
else{
printf("请等待\n");
A->length++;
A->rear = A->rear->next;
}
}
void InGJJ(LQueueBank *A, LQueueBank *B){
if(B->length
B->length++;
printf("办理中\n");
}
else{
printf("请等待\n");
A->length++;
A->rear = A->rear->next;
}
}
void InYHK(LQueueBank *A, LQueueBank *B){
if(B->length
B->length++;
printf("办理中\n");
}
else{
printf("请等待\n");
A->length++;
A->rear = A->rear->next;
}
}
void Leave(LQueueBank *A, LQueueBank *B,LQueueBank *C,LQueueBank *D,LQueueBank *E,LQueueBank *F){
printf("请输入离开用户所在窗口\n");
int yw;
scanf("%d",&yw);
switch(yw){
case 1:
{
A->rear = A->head;A->length--;
if(D->length > 0) {
printf("请等待办理公积金的第一位用户来窗口1办理\n");
InGJJ(D,A);
}
break;
}
case 2:case 3:case 4:
{
B->rear = B->head->next->next;B->length--;
if(E->length > 0){
printf("请等待办理银行卡的第一位用户来窗口%d办理\n",yw); InYHK(E,B);
}
else if (F->length > 0) {
printf("请等待办理理财卡的第一位用户来窗口%d办理\n",yw); InLCK(F,C,B);
}
break;
}
case 5: case 6:
{
C->length--; C->rear = C->head->next;
if(F->length > 0) InLCK(F,C,B);
printf("请等待办理理财卡的第一位用户来窗口%d办理\n",yw);
break;
}
default: printf("输入有误,请重试!\n");
}
}
void PRINT(LQueueBank *A, LQueueBank *B,LQueueBank *C){
if(A->length == 0) printf("1号窗口空闲中\n");
else printf("1号窗口忙碌中\n");
if(B->length == 0) printf("2号窗口空闲中\n3号窗口空闲中\n4号窗口空闲中\n"); else if(B->length == 1) printf("2号窗口忙碌中\n3号窗口空闲中\n4号窗口空闲中\n"); else if(B->length == 2) printf("2号窗口忙碌中\n3号窗口忙碌中\n4号窗口空闲中\n"); else if(B->length == 3) printf("2号窗口忙碌中\n3号窗口忙碌中\n4号窗口忙碌中\n");
if(C->length == 0) printf("5号窗口空闲中\n6号窗口空闲中\n");
else if(C->length == 1) printf("5号窗口忙碌中\n6号窗口空闲中\n");
else if(C->length == 2) printf("5号窗口忙碌中\n6号窗口忙碌中\n");
}
void main()
{
LQueueBank Wait1,Wait2,Wait3,Busy1,Busy2,Busy3; //1:公积金 2:银行卡 3:理财卡 Wait1 = InitQueue(&Wait1);
Wait2 = InitQueue(&Wait2);
Wait3 = InitQueue(&Wait3);
Busy1 = InitQueue(&Busy1);
Busy2 = InitQueue(&Busy2);
Busy3 = InitQueue(&Busy3);
int ch = 0;
while(1)
{
printf("----------------------------------\n");
printf("1. 办理业务 ");
printf("2. 完成离开 ");
printf("3. 退出 ");
printf("0. 打印当前窗口状态\n");
while(1)
{
scanf("%d",&ch);
if(ch>=0&&ch
else
printf("\n输入有误,请重试!");
}
switch(ch)
{
case 0:{PRINT(&Busy1,&Busy2,&Busy3);break;}
case 1:{
printf("请输入业务种类1/2/3\n");
printf("1. 公积金 2. 银行卡 3. 理财卡\n");
int yw1;
scanf("%d",&yw1);
switch(yw1){
case 1: {InGJJ(&Wait1,&Busy1);break;}
case 2: {InYHK(&Wait2,&Busy2);break;}
case 3: {InLCK(&Wait3,&Busy3,&Busy2);break;}
default: printf("输入有误,请重试!\n");
}
break;
}
case 2:{
Leave(&Busy1,&Busy2,&Busy3,&Wait1,&Wait2,&Wait3);
break;
}
case 3:exit(0); default: break; }
}
}
2.运行窗口截图: