数据结构_银行排队问题

/*
某银行营业厅共有6个营业窗口,设有排队系统广播叫号,该银行的业务分为公积金、银行卡、理财卡等三种。公积金业务指定1号窗口,银行卡业务指定2、3、4号窗口,理财卡业务指定5、6号窗口。但如果5、6号窗口全忙,而2、3、4号窗口有空闲时,理财卡业务也可以在空闲的2、3、4号窗口之一办理
客户领号、业务完成可以作为输入信息,要求可以随时显示6个营业窗口的状态。
*/
1.源程序
#include<stdio.h>
#include<stdlib.h>
#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){
WIFI智能连接    if(B->length < 2){
        B->length++;
圆珠笔尖        printf("办理中\n");
    }
    else if(C->length < 3){
        C->length++;
        printf("办理中\n");
    }
    else{
        printf("请等待\n");
        A->length++;
        A->rear = A->rear->next;
    }   
}
void InGJJ(LQueueBank *A, LQueueBank *B){
    if(B->length < 1){
        B->length++;
性引诱        printf("办理中\n");
    }
    else{
        printf("请等待\n");
        A->length++;
        A->rear = A->rear->next;
    }
   
}
void InYHK(LQueueBank *A, LQueueBank *B){
    if(B->length < 3){
        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<=3) break;
                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");
                  }

本文发布于:2024-09-22 01:40:57,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/3/171306.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:业务   输入   营业   理财   办理   公积金
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议