• 大小: 2KB
    文件类型: .cpp
    金币: 1
    下载: 0 次
    发布日期: 2021-05-23
  • 语言: C/C++
  • 标签: 源代码  数据结构  

资源简介

/* 假设只有一个医生,在一段时间内随机地来几位病人;假设病人到达的时间间隔为0-14分钟 之间的某个随机值,每个病人所需处更有时间为1-9分钟之间的某个随机值。试用队列结构进行模拟。 */ #include #include #include #include typedef struct { int arrive; int treat; }PATIENT; typedef struct queue { PATIENT data; struct queue *link; }QUEUE; ………… ……

资源截图

代码片段和文件信息

/*
假设只有一个医生,在一段时间内随机地来几位病人;假设病人到达的时间间隔为0-14分钟
之间的某个随机值,每个病人所需处更有时间为1-9分钟之间的某个随机值。试用队列结构进行模拟。
*/


#include
#include
#include
#include


typedef struct
{
int arrive;
int treat;
}PATIENT;

typedef struct queue
{
PATIENT data;
struct queue *link;
}QUEUE;


void EnQueue(QUEUE **headQUEUE **tailPATIENT x)
//进队操作
{
QUEUE *p;
p=(QUEUE*)malloc(sizeof(QUEUE));
p->data=x;
p->link=NULL;
if(*head==NULL)
*head=*tail=p;
else
{
(*tail)->link=p;
*tail=p;
}
}


int DeQueue(QUEUE **headQUEUE **tailPATIENT *cp)
//出队操作
{
QUEUE *p;
p=*head;
if(*head==NULL)
return 1;
*cp=(*head)->data;
*head=(*head)->link;
if(*head==NULL)
*tail=NULL;
free(p);
return 0;
}

void OutputQueue(QUEUE *head)
{
while(head!=NULL)
{
printf(“到达时间:[%d]处理时间:[%d]\n“head->data.arrivehead->data.treat);
head=head->link;
}
}


void InitData(PATIENT *paint n)
{
int parr=0;
int i;
for(i=0;i {

评论

共有 条评论

相关资源