银行小系统程序

vivid_xi 28 0 TXT 2019-01-02 00:01:21

#include #include #include #define M 30 typedef struct{ int elem[M]; //定义一个数组 int front; //定义头指针 int rear; //定义尾指针 int length;//定义长度 }Queue; init(Queue *s) { s->front =-1;//首尾指针都为-1,长度为0 s->rear =-1; s->length =0; } int inQueue(Queue *s,int n)//在队列的尾部进行插入(考虑到队列长度和在哪里插入的问题) { if(s->length >= M) { printf("队列太长,请稍后!"); return 0; } s->rear ++;//尾指针后移 s->elem [s->rear ]=n; if(s->front ==-1) //如果没有元素,就把头指针后移 { s->front + +; } s->length ++; //每加入一个元素,队列的长度都要加1 return 1; } int outQueue(Queue *s )//把头指针后移,然后长度减1 { int n; if(s->length ==0) printf("没有人排队!"); else { n=s->elem [s->front ]; s->front ++; s->length --; printf("前面的%d已经服务好",n); return 1; } } void print( Queue *s) { printf("你的排队号码是%d",s->elem [s->front ]); } void show() { printf("*******欢迎来到银行系统********\n"); printf("1: 请您到取号机取号码,根据号码排队 \n"); printf("2: 办理完成,下一位\n"); printf("3: 退出\n"); printf("**************************\n"); } void main() { Queue q;int x=0;char ch; init(&q); while(1) { show(); ch=getchar(); switch(ch) { case '1': printf("你的排队号码是%d",++x); if(x>M) printf("现在排队的人太多,请稍候!"); inQueue(&q,x); ch=getchar(); break; case '2':outQueue(&q); ch=getchar(); break; case '3':exit(0); ch=getchar(); break; default:printf("输入命令错误,请重新输入!"); ch=getchar(); } } } +; } s->length ++; //每加入一个元素,队列的长度都要加1 return 1; } int outQueue(Queue *s )//把头指针后移,然后长度减1 { int n; if(s->length ==0) printf("没有人排队!"); else { n=s->elem [s->front ]; s->front ++; s->length --; printf("前面的%d已经服务好",n); return 1; } } void print( Queue *s) { printf("你的排队号码是%d",s->elem [s->front ]); } void show() { printf("*******欢迎来到银行系统********\n"); printf("1: 请您到取号机取号码,根据号码排队 \n"); printf("2: 办理完成,下一位\n"); printf("3: 退出\n"); printf("**************************\n"); } void main() { Queue q;int x=0;char ch; init(&q); while(1) { show(); ch=getchar(); switch(ch) { case '1': printf("你的排队号码是%d",++x); if(x>M) printf("现在排队的人太多,请稍候!"); inQueue(&q,x); ch=getchar(); break; case '2':outQueue(&q); ch=getchar(); break; case '3':exit(0); ch=getchar(); break; default:printf("输入命令错误,请重新输入!"); ch=getchar(); } } }

银行小系统程序

用户评论
请输入评论内容
评分:
暂无评论