队列操作的接口:http://blog.csdn.net/qlx846852708/article/details/43666927
数据结构C语言实现:http://blog.csdn.net/qlx846852708?viewmode=contents
本文件是用队列实现银行排队系统,上面的连接是我实现的队列的接口实现。
#include <stdio.h> #include <stdlib.h> #include <string.h> #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\n"); 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\n"); return -1; } data = queue_pop(queue); printf("0x%x\n",data); printf("please number is %d handles the service\n",data->number); } int menu() { printf("********************\n"); printf("1.new consumer\n"); printf("2.next consumer\n"); printf("0.quit "); printf("\n"); printf("********************\n"); } int main() { int opt = 0; int len = 0; DATATYPE_T data; SEQQUEUE *queue=NULL; queue = queue_init(); if(queue==NULL) { printf("creat queue failed\n"); return -1; } do { menu(); printf("please input select!\n"); scanf("%d",&opt); switch(opt) { case 1: add_queue(queue); len = get_queue_length(queue); printf("current wait for %d consumer\n",len); break; case 2: next(queue); len = get_queue_length(queue); printf("current wait for %d consumer\n",len); break; case 0: break; default: break; } }while(opt!=0); return 0; }
原文地址:http://blog.csdn.net/qlx846852708/article/details/43730153