码迷,mamicode.com
首页 > 编程语言 > 详细

C语言学习之用队列实现银行排队系统

时间:2015-02-11 09:23:59      阅读:483      评论:0      收藏:0      [点我收藏+]

标签:c语言   队列   接口   


队列操作的接口: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;
}



C语言学习之用队列实现银行排队系统

标签:c语言   队列   接口   

原文地址:http://blog.csdn.net/qlx846852708/article/details/43730153

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!