/*
* Copyright (c)2016,烟台大学计算机与控制工程学院
* All rights reserved.
* 文件名称:项目3.cbp
* 作 者:王婧
* 完成日期:2016年12月29日
* 版 本 号:v1.0
* 问题描述:银行叫号机
(1)模拟银行开关门时间。(2)模拟最基础的叫号功能
* 输入描述:无
* 程序输出:测试数据
*/
liqueue.p
#ifndef SQQUEUE_H_INCLUDED
#define SQQUEUE_H_INCLUDED
#include<time.h>
#include <stdio.h>
#include <malloc.h>
#define MaxSize 5
typedef int ElemType;
typedef struct TimeBank
{
int h;
int m;
int s;
} timeBank; //记录某一刻的时间
typedef struct qnode //数据节点
{
ElemType data;//名次
ElemType data1;//业务类型
struct qnode *next;
} QNode;
typedef struct //链队节点
{
QNode *front;
QNode *rear;
} LiQueue;
void CloseBank();//银行已经下班的操作函数
void NoCloseBank();//银行未开门的操作函数
void InitQueue(LiQueue *&q); //初始化链队
void DestroyQueue(LiQueue *&q); //销毁链队
bool QueueEmpty(LiQueue *q); //判断链队是否为空
int QueueLength(LiQueue *q); //返回队列中元素个数,也称队列长度
int EntertimeBank(char c[]);//判断开输入开关门时间是否合法
void enQueue(LiQueue *&q,ElemType e,ElemType a); //进队
bool deQueue(LiQueue *&q,ElemType &e,ElemType &a); //出队
timeBank GetTimeBank();//取系统当前的时间
#endif // SQQUEUE_H_INCLUDED
liqueue.cpp
//链队基本运算函数
#include "liqueue.h"
void CloseBank()//银行已经下班的操作函数
{
printf("\n尊敬的客户你好!!\n银行已经下班,请您明天再来!!!谢谢光临!!!\n");
}
void NoCloseBank()//银行未开门的操作函数
{
printf("\n尊敬的客户,您好!银行还未开门,请您稍等片刻!!!\n");
}
void InitQueue(LiQueue *&q) //初始化链队
{
q=(LiQueue *)malloc(sizeof(LiQueue));
q->front=q->rear=NULL;
}
timeBank GetTimeBank()//取系统当前的时间
{
time_t timep;//取系统时间
struct tm *p;
time(&timep);
p=localtime(&timep); /*取得当地时间*/
//printf ("当前系统时间为:%d/%d/%d ", (1900+p->tm_year),( 1+p->tm_mon), p->tm_mday);
//printf("%d:%d:%d\n",p->tm_hour, p->tm_min, p->tm_sec);
timeBank t;//t是当前系统时间
t.h= p->tm_hour;
t.m= p->tm_min;
t.s= p->tm_sec;
return(t);
}
void DestroyQueue(LiQueue *&q) //销毁链队
{
QNode *p=q->front,*r; //p指向队头数据节点
if (p!=NULL) //释放数据节点占用空间
{
r=p->next;
while (r!=NULL)
{
free(p);
p=r;
r=p->next;
}
}
free(p);
free(q); //释放链队节点占用空间
}
bool QueueEmpty(LiQueue *q) //判断链队是否为空
{
return(q->rear==NULL);
}
int QueueLength(LiQueue *q) //返回队列中数据元素个数
{
int n=0;
QNode *p=q->front;
while (p!=NULL)
{