1 / 12
文档名称:

数据结构-病人看病排队模拟程序c语言版.doc

格式:doc   大小:37KB   页数:12页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

数据结构-病人看病排队模拟程序c语言版.doc

上传人:endfrs 2018/9/7 文件大小:37 KB

下载得到文件列表

数据结构-病人看病排队模拟程序c语言版.doc

文档介绍

文档介绍:#include<>
#include<>
#include<>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef struct QNode{
int data;
struct QNode *next;
}QNode,*QueuePtr;
struct LinkQueue{
QueuePtr front;
QueuePtr rear;
};
LinkQueue Q;
int deletedCount = 0;
void menu();
void QueueUp();
void Treatment();
void Display();
void Count();
Status QueueEmpty(LinkQueue);
//初始化队列
Status InitQueue(LinkQueue &Q){
= = (QueuePtr)malloc(sizeof(QNode));
if(!) exit(OVERFLOW);
-> next = NULL;
return OK;
}
//在队尾插入新元素
Status EnQueue(LinkQueue &Q,int e){
QueuePtr p;
p = (QueuePtr)malloc(sizeof(QNode));
if(!p) exit(OVERFLOW);
p -> data = e;
p -> next = NULL;
-> next = p;
= p;
return OK;
}
//删除对头元素
Status DeQueue(LinkQueue &Q,int &e){
QNode *p;
if(QueueEmpty(Q)) return ERROR;
p = -> next;
e = p -> data;
-> next = p -> next;
if( == p)
= ;
free(p);
deletedCount++;
return OK;
}
//求队列中元素的个数
int QueueLength(LinkQueue Q){
QueuePtr p;
int length = 0;
if( == NULL) exit(ERROR);
p = ;
while(p != ){
length++;
p = p -> next;
}
return length;
}
//检查是否为空队列
Status QueueEmpty(LinkQueue Q){
return == ;
}
//排队
void QueueUp(){
int newNum,count;
//printf("QueueUp");
//InitQueue(Q);
printf("\n\n\n\t\t请输入病历号:");
scanf ("%d",&newNum);
EnQueue(Q,newNum);
count = QueueLength(Q);
//成功插入元素后,显示排在前面总共有多少人
printf("\n\n\n\t\t您排在队伍里第%d 位\n\t\t前面还有%d 位病人.",count,count - 1);
printf("\n\n\t\t请按任意键返回主菜单\n\n\n");
system("pause");
getchar();
system("CLS");
menu();
}
//就诊
void Treatment(){
int e;
//printf("Treatment");
if(!QueueEmpty(Q)){
DeQueue(Q,e);
printf("\n\n\n\t请病历号为%d 的病人接受就诊.",e);
}
else
printf("\n\n\t\t当前没有病人在排队!");
printf("\n\n\t请按任意键返回主菜单\n\n\n");
system("pause");
getchar();
system("CLS");
menu();
}
//查看排队
vo