#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("***************银行叫号系统模拟***************\n");
    printf("0 :  上班\n");
    printf("1 :  排号\n");
    printf("2 :  叫号\n");
    printf("3 :  下班\n");
    printf("************************************************\n");

    while(scanf("%d", &n),n)
    {
        printf("亲,您还没有开始上班哦~\n");
    }
   
    printf("美好的一天从上班开始啦~\n");
    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个人.请耐心等待.\n", f, s.rear-s.top-1);
            f++;
        }
        else if(n==2)
        {
            if(!QueueEmpty(s)) printf("当前没有办理业务的人员.\n");
            else
            {
                Pop(&s, &e);
                printf("请号码为%d的顾客前来办理业务.\n", e);
            }
        }
    }
    printf("终于下班啦~为辛苦一天的自己点赞.\n");
    return 0;
}

 

posted on 2016-10-20 20:14  不忧尘世不忧心  阅读(357)  评论(0编辑  收藏  举报