C Language Learning: Using queues to implement a bank Queuing System
This document uses queues to implement the bank queuing system. The above connection is implemented by the queue interface I implemented.
#include
#include
#include
#include seqQueue.hint g_number = 0;int add_queue(SEQQUEUE *queue){ int ret = 0; int number = 0; DATATYPE_T data; ret = queue_full(queue); if(ret==0) { data.number = ++g_number; data.time = time(NULL); queue_push(queue,data); } else { printf(line up too much,please waiting); return -1; } return 0;}void next(SEQQUEUE *queue){ int ret = 0; DATATYPE_T *data; ret = queue_empty(queue); if(ret) { printf(the queue is empty); return -1; } data = queue_pop(queue); printf(0x%x,data); printf(please number is %d handles the service,data->number);}int menu(){ printf(********************); printf(1.new consumer); printf(2.next consumer); printf(0.quit ); printf(); printf(********************);}int main(){ int opt = 0; int len = 0; DATATYPE_T data; SEQQUEUE *queue=NULL; queue = queue_init(); if(queue==NULL) { printf(creat queue failed); return -1; } do { menu(); printf(please input select!); scanf(%d,&opt); switch(opt) { case 1: add_queue(queue); len = get_queue_length(queue); printf(current wait for %d consumer,len); break; case 2: next(queue); len = get_queue_length(queue); printf(current wait for %d consumer,len); break; case 0: break; default: break; } }while(opt!=0); return 0;}
??