zoukankan      html  css  js  c++  java
  • 栈的应用之银行叫号系统模拟

      #include <stdio.h>
    
    #define STACKSIZE 110
    #define TRUE 1
    #define FALSE 0
    
    typedef int ElemType;
    typedef int Status;
    typedef struct
    {
        ElemType data[STACKSIZE];
        int top;
        int rear;
    } SeqQueue;
    
    Status QueueEmpty(SeqQueue s)
    {
        if(s.top==s.rear) return FALSE;
        return TRUE;
    }
    
    void InitQueue(SeqQueue *s)
    {
        (*s).top=0;
        (*s).rear=0;
    }
    
    void Push(SeqQueue *s, int f)
    {
       (*s).data[(*s).rear]=f;
       (*s).rear++;
    }
    
    void Pop(SeqQueue *s, int *e)
    {
          *e=(*s).data[(*s).top];
          (*s).top++;
    }
    
    int main()
    {
        int n;
        int e, f=1;
        SeqQueue s;
        printf("***************银行叫号系统模拟***************
    ");
        printf("0 :  上班
    ");
        printf("1 :  排号
    ");
        printf("2 :  叫号
    ");
        printf("3 :  下班
    ");
        printf("************************************************
    ");
    
        while(scanf("%d", &n),n)
        {
            printf("亲,您还没有开始上班哦~
    ");
        }
       
        printf("美好的一天从上班开始啦~
    ");
        InitQueue(&s);
    
        while(scanf("%d", &n), n!=3)
        {
            if(!n)
            {
             printf("您已经开始上班了哦~"):
                 continue;
            }
            if(n!=1 && n!=2 && n!=3)
            {
             printf("请输入有效的指令!");
             continue;
            }
            if(n==1)
            {
                Push(&s, f);
                printf("您的号码为%d,您前面共有%d个人.请耐心等待.
    ", f, s.rear-s.top-1);
                f++;
            }
            else if(n==2)
            {
                if(!QueueEmpty(s)) printf("当前没有办理业务的人员.
    ");
                else
                {
                    Pop(&s, &e);
                    printf("请号码为%d的顾客前来办理业务.
    ", e);
                }
            }
        }
        printf("终于下班啦~为辛苦一天的自己点赞.
    ");
        return 0;
    }
  • 相关阅读:
    python入门之函数及其方法
    Python入门知识点2---字符串
    Python列表 元组 字典 以及函数
    Python入门知识
    Autofac使用代码
    优化EF以及登录验证
    CRM框架小知识以及增删查改逻辑代码
    分页SQL
    触发器SQL
    动态生成lambda表达式
  • 原文地址:https://www.cnblogs.com/daydayupacm/p/5982249.html
Copyright © 2011-2022 走看看