循环队列实现业务办理流程基本功能
来源:互联网 发布:软件企业名称变更流程 编辑:程序博客网 时间:2024/04/28 00:04
循环队列与顺序队列功能基本一致但就队的长度等方面略有不同,下面通过一个功能实现来体现它的基本操作
#define QueueMax 15typedef struct{ DATA data[QueueMax]; int head; int tail;} CycQueue;CycQueue *CycQueueInit(){ CycQueue *q; if(q=(CycQueue *)malloc(sizeof(CycQueue))) { q->head = 0; q->tail = 0; return q; } else return NULL; }void CycQueueFree(CycQueue *q){ if(q!=NULL) { free(q); }} //检验队列是否为空int CycQueueIsEmpty(CycQueue *q){ return (q->head == q->tail);}//队列是否已满int CycQueueIsFull(CycQueue *q){ return ((q->tail+1)%QueueMax==q->head);}//顺序队列的入队操作int CycQueueIn(CycQueue *q,DATA data){ if((q->tail+1)%QueueMax==q->head) { printf("队列已满"); return 0; } else { q->tail=(q->tail+1)%QueueMax; q->data[q->tail]=data; return 1; }} DATA *CycQueueOut(CycQueue *q){ if(q->head ==q->tail) { printf("队列已空"); return NULL; } else { q->head = (q->head+1)%QueueMax; return &(q->data[q->head]);//取出队头元素后,将队头指针加一 }} DATA *CycQueuePeek(CycQueue *q){ if(q->head ==q->tail) { printf("队列已空"); return NULL; } else { return &(q->data[(q->head+1)%QueueMax]);//取出队头元素后,将队头指针加一 }} int CycQueueLen(CycQueue *q){ return (q->tail-q->head);}
#include "stdio.h"#include "stdlib.h"#include "time.h"typedef struct{ int num;//顾客编号 long time;//进入队列时间 }DATA;#include "CycQueue.c"int num;//顾客编号void add(CycQueue *q){ DATA data; if(!CycQueueIsFull(q)) { data.num ==++num; data.time = time(NULL); CycQueueIn(q,data); } else printf("/n排队人太多,等待,,,,,");} void next(CycQueue *q){ DATA *data; if(!CycQueueIsEmpty(q)) { data = CycQueueOut(q); printf("请编号为%d的顾客办理业务\n",data->num); } if(!CycQueueIsEmpty(q)) { data = CycQueuePeek(q); printf("请编号为%d的顾客,马上为您办理业务\n",data->num); }} int main(){ CycQueue *queue1; int i,n; char select; num=0; queue1=CycQueueInit(); if(queue1==NULL) { printf("创建队列时出错\n"); getch(); return 0; } do{ printf("\n请选择具体操作:\n"); printf("1.新到客户\n"); printf("2.下一个客户\n"); printf("0.退出\n"); fflush(stdin); scanf("%d",&select); switch(select) { case 1: add(queue1); printf("\n现在共有%d位客户在等待",CycQueueLen(queue1)); break; case 2: next(queue1); printf("\n现在共有%d位客户在等待",CycQueueLen(queue1)); break; case 0: break; } }while(select!=0); CycQueueFree(queue1);//释放 getch(); return 0; }
0 0
- 循环队列实现业务办理流程基本功能
- 循环队列的基本功能实现
- 模拟招商银行叫号业务办理流程
- 实现队列基本功能
- 业务办理
- Java -- 队列(模拟银行的排队办理业务)
- 模拟港澳通行证办理流程系统(队列基础练习)
- 从银行窗口业务办理来看锁的实现
- 链式队列基本功能的简单实现
- 用自定义的队列实现一些基本功能
- 链表队列基本功能的实现
- [PAT甲级]1014. Waiting in Line (30)(银行排队办理业务结束时间 队列的应用)
- 思考mysql内核之初级系列3---办理业务的流程
- 思考mysql内核之初级系列3---办理业务的流程
- 思考mysql内核之初级系列3---办理业务的流程(摘自老杨)
- 思考mysql内核之初级系列3---办理业务的流程
- 队列----循环数组实现队列
- 队列----循环队列的实现
- gem5中运行spec2006
- Leetcode 89 Gray Code
- 素数筛法
- 系统分析师笔记-数据通信和网络
- C#实现毛玻璃效果
- 循环队列实现业务办理流程基本功能
- [android那些事] linux 下android源码编译(国内被墙方案)
- html基本字体元素,排版标签,列表元素,html字符实体,字符编码原理
- CentOS6下安装oracle 12c,遭遇[INS-20802] Oracle Net Configuration Assistant failed.
- 结构与union
- 编译原理笔记
- LeetCode 9 - Palindrome Number
- JTabbedPane选项窗格的使用
- CodeForces 534B Covered Path 【贪心】