📄 sy3_5.c
字号:
/* sy3_5.c */
#include "sj.h"
typedef struct elm
{ int No; /*号码*/
long Tim ; /*顾客进入银行的时间*/
char classifi; /*业务类型*/
int pre; /*队列前面的人数*/
} ElemType;
typedef struct node
{ ElemType data;
struct node *next;
} QNode; /* 链队列结点的类型 */
typedef struct
{ QNode *front,*rear ;
}LQueue; /* 将头尾指针封装在一起的链队列 */
char ch;
int i1=0,i2=0,i3=0; /*记录各业务队列前面还没有办理的人数*/
long t1; /*用t1记录登记时间*/
int y,pre1=0,pre2=0,pre3=0;
LQueue *qa,*qb,*qc; /*分别代表团体业务、证券业务和个人业务队列*/
LQueue *qa1,*qa2,*qb1,*qb2,*qc1,*qc2; /*分别代表各窗口队列*/
ElemType e;
void InitQueue(LQueue *q) /*初始化队列*/
{
q->front=q->rear=NULL;
}/*InitQueue*/
Status EmptyQueue(LQueue *Lq)
{
if(Lq->front==NULL) return 1;
else return 0;
}
void EnQueue(LQueue *Lq,ElemType e) /*进队操作*/
{
QNode *newnode=(QNode *)malloc(sizeof(QNode));
newnode->data=e;
newnode->next=NULL;
if(Lq->rear==NULL) /*若队列为空*/
Lq->front=Lq->rear=newnode;
else
{
Lq->rear->next=newnode;
Lq->rear=newnode;
}
} /* EnQueue*/
Status OutQueue(LQueue *Lq,ElemType *d) /*出队操作*/
{
ElemType temp;
QNode *p;
if(Lq->front==NULL)
{
printf("The Queue is empty!(队列已空!)\n");
return OVERFLOW ;
}
*d=Lq->front->data;
p=Lq->front;
Lq->front=p->next;
if(Lq->front==NULL) Lq->rear=NULL; /*如果出队后队列为空,则队尾也变为空*/
free(p);
return OK;
}
void ManEnQueue() /*客户排队登记*/
{
printf("请输入客户办理业务类型:a、b或c\na:团体业务\nb:证券业务\nc:个人业务\n请输入(如果输入d则结束输入):");
getchar();
scanf("%c",&ch);
printf("ch=%c",ch);
while(ch>='a' && ch<'d')
{
switch(ch)
{
case 'a':e.No=++i1;e.classifi='a'; e.pre=pre1++;
EnQueue(qa,e);
break; /* 办理团体业务的客户进qa队 */
case 'b':e.No=++i2;e.classifi='b'; e.pre=pre2++;
EnQueue(qb,e);
break; /* 办理证券业务的客户进qb队 */
case 'c':e.No=++i3;e.classifi='c'; e.pre=pre3++;
EnQueue(qc,e);
break; /* 办理个人业务的客户进qc队*/
};/* switch(ch)*/
Printele(e); /*显示前来办理业务的类型及号码*/
printf("请输入客户办理业务的类型: a、b、c或d:");
getchar();
scanf("%c",&ch);
}/*while(ch)*/
}
void ManEnbar() /*根据情况到不同的窗口办理业务*/
{
do
{
printf("请输入柜员号0-6:\n");
scanf("%d",&y);
if(y<0|| y>6)
printf("柜员号错误,请重新输入!\n");
else
{ switch(y)
{
case 1:
if(OutQueue(qa,&e)==OK)
{ pre1--;
EnQueue(qa1,e);Printele(e); i1--; }
else
printf("没有任何等待办理业务的顾客了! \n");
break;
case 2:
if(OutQueue(qa,&e)==OK)
{pre1--;EnQueue(qa2,e);Printele(e); i1--; }
else
printf("没有任何等待办理业务的顾客了! \n");
break;
case 3:
if(OutQueue(qb,&e)==OK)
{pre2--;EnQueue(qb1,e);Printele(e); i2--;}
else
printf("没有任何等待办理业务的顾客了! \n");
break;
case 4:
if(OutQueue(qb,&e)==OK)
{pre2--;EnQueue(qb2,e);Printele(e); i2--;}
else
printf("没有任何等待办理业务的顾客了! \n");
break;
case 5:
if(OutQueue(qc,&e)==OK)
{ pre3--;EnQueue(qc1,e);Printele(e); i3--;
}
else
printf("没有任何等待办理业务的顾客了! \n");
break;
case 6:
if(OutQueue(qc,&e)==OK)
{ pre3--;EnQueue(qc2,e);Printele(e); i3--;
}
else
printf("没有任何等待办理业务的顾客了! \n");
break;
default:break;
}/*switch(y)*/
}/*else*/
}while(y!=0); /*do while*/
}
int Printele(ElemType e) /*显示前来办理业务的类型及号码*/
{
printf("\n *****Bank(银行)\n");
printf("Business number is:(业务的类型:)%d\n",e.No);
printf("Business type is:(业务的类型:)%c\n",e.classifi);
printf("还有%d个顾客在前面等待!\n",e.pre);
return OK;
}
Status Printz(LQueue *Lq) /*输出每个窗口所办理业务的情况*/
{
int iii=0;
QNode *p;
p=Lq->front;
while(p!=NULL)
{ iii++;
printf("%d Number=%d Leixing=%c\n",iii,p->data.No,p->data.classifi);
p=p->next ;
}
return OK;
}/*Printz*/
void main()
{ int flag;/*flag: 用户输入, mark:*/
qa=(LQueue *)malloc(sizeof(LQueue));
qb=(LQueue *)malloc(sizeof(LQueue));
qc=(LQueue *)malloc(sizeof(LQueue));
InitQueue(qa); InitQueue(qb); InitQueue(qc);
qa1=(LQueue *)malloc(sizeof(LQueue));
qa2=(LQueue *)malloc(sizeof(LQueue));
qb1=(LQueue *)malloc(sizeof(LQueue));
qb2=(LQueue *)malloc(sizeof(LQueue));
qc1=(LQueue *)malloc(sizeof(LQueue));
qc2=(LQueue *)malloc(sizeof(LQueue));
InitQueue(qa1); InitQueue(qa2); InitQueue(qb1);
InitQueue(qb2); InitQueue(qc1); InitQueue(qc2);
do{
printf("Function table:(功能表:)\n");
printf("1---Client register(客户到银行进行登记)\n");
printf("2---Staff calls(柜员叫号)\n");
printf("0---The end.结束程序运行\n");
printf(" Please select:(请输入功能号:)");
scanf("%d",&flag);
if(flag<0 || flag>2)
printf("It's error, Please input again!(功能号错误,请重新输入!)\n");
else
if (flag==1)
ManEnQueue();
else
if(flag==2)
ManEnbar(); /*柜员叫号,客户根据情况到不同的窗口办理业务*/
/*if switch*/
}while(flag!=0);/*外层do循环结束*/
printf("Reasult总结\n");
printf("队列qa1中的元素是: \n"); Printz( qa1);
printf("队列qa2中的元素是: \n"); Printz( qa2);
printf("队列qb1中的元素是: \n"); Printz( qb1);
printf("队列qb2中的元素是: \n"); Printz( qb2);
printf("队列qc1中的元素是: \n"); Printz( qc1);
printf("队列qc2中的元素是: \n"); Printz( qc2);
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -