本文件是用隊列實現銀行排隊系統,上面的連接是我實現的隊列的接口實現。
#include#include #include #include seqQueue.h int 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; }
??