資源簡介
一個醫務室的代碼 轉的
#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 {
pa[i].arrive=
評論
共有 條評論