Status EnQueue(WQueue &Q,QElemType e) { QueuePtr p; p=new QNode; if(!p) return OVERFLOW; p->data=e;p->next=NULL; Q.rear->next=p; Q.rear=p; return OK; }
Status DeQueue(WQueue &Q,QElemType &e) { QueuePtr p; if(Q.front==Q.rear) return ERROR; p=Q.front->next; e=p->data; Q.front->next=p->next; if(Q.rear==p) Q.rear=Q.front; free(p); return OK; }
Status QueueEmpty(WQueue Q) { if(Q.front==Q.rear) return TRUE; else return FALSE; }
Status QDelNode(WQueue &Q,QueuePtr p) { QueuePtr q; if(p==NULL||p->next==NULL) return ERROR; q=p->next; p->next=q->next; if(p->next==NULL) Q.rear=p; DestoryClient(q->data); free(p); return OK; }
Status CGiveUp(WQueue &Q,int floor) { QueuePtr p; p=Q.front;
if(p->next!=NULL) if(p->next->data->GivepuTime==0&&floor!=p->next->data->Infloor) { PrintClientInfo(*(p->next->data),GiveUp); TotalTime+=Time-CInTime(*(p->next->data)); QDelNode(Q,p); GiveUpNumber++; } else p->next->data->GivepuTime--; return OK; }
void PrintQueue(WQueue Q) { QueuePtr q; int count=0; if(Q.front->next==NULL) goto end; q=Q.front->next; while(q!=NULL) { cout<
void InOut(Elevator &E,WQueue w[Maxfloor+1][2]) { Client *p; if(E.CallCar[E.floor]) if(StackEmpty(E.S[E.floor])) E.CallCar[E.floor]=0; else { Pop(E.S[E.floor],p);E.ClientNumber--; InOutCount=InOutTime; PrintClientInfo(*p,Out); TotalTime+=Time-CInTime(*p); DestoryClient(p); } if(E.CallCar[E.floor]==0)
if(!QueueEmpty(w[E.floor][E.Stage])) { DeQueue(w[E.floor][E.Stage],p); Push(E.S[COutfloor(*p)],p); if(E.CallCar[COutfloor(*p)]!=1) { E.CallCar[COutfloor(*p)]=1; } E.ClientNumber++; InOutCount=InOutTime; PrintClientInfo(*p,In); } else { if(E.Stage==Down) E.CallDown[E.floor]=0; else E.CallUp[E.floor]=0; } }
void NewClient(Elevator &E,WQueue w[5][2]) { Client *p; CreatClient(p); if(GoAbove(*p)) { EnQueue(w[CInfloor(*p)][Up],p);E.CallUp[CInfloor(*p)]=1; } else { EnQueue(w[CInfloor(*p)][Down],p);E.CallDown[CInfloor(*p)]=1; } }
void Print(Elevator &E,Action a) { switch(a) { case DoorOpened:printf(\电梯门已打开.\\n\ case DoorClosed:printf(\电梯门已关闭.\\n\ case Achieved:printf(\电梯已到达第%d层。\\n\ case GoingUp:printf(\电梯上升中...\\n\ case GoingDown:printf(\电梯下降中...\\n\
default:break; };
}
int main() { Elevator E; printf(\ \ ^^欢迎使用电梯模拟系统^^ \\n\
\
\^^^^^\\n\ WQueue w[Maxfloor+1][2]; InitEle(E); srand( (unsigned)time( NULL )); for(int i=0;i<=Maxfloor;i++) { InitQueue(w[i][Up]); InitQueue(w[i][Down]); } MaxTime=1000000; printf(\请输入电梯的运行时间:\
scanf(\while(Time++ } } printf(\共%d人进入系统,\ printf(\共%d人放弃。\DestoryEle(E); for(i=0;i<=Maxfloor;i++) { DestroyQueue(w[i][Up]); DestroyQueue(w[i][Down]); } return 0; 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库电梯模拟系统(4)在线全文阅读。
相关推荐: