编写病人医院看病模拟程序
生活随笔
收集整理的這篇文章主要介紹了
编写病人医院看病模拟程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目的:掌握隊列應用的算法設計。
內容:編寫一個程序exp3-4.cpp,反應病人到醫院排隊看醫生的情況。在病人排隊過程中重復下面兩件事。
要求模擬病人等待就診這一過程。程序采用菜單方式,其選項及功能說明如下。
1:排隊——輸入排隊病人的病歷號,加入病人排隊隊列中。
2:就診——病人排隊隊列中最前面的病人就診,并將其從隊列中刪除。
3:查看隊列——從隊首到隊尾列出所有排隊病人的病歷號。
4:不再排隊,余下依次就診——從隊首到隊尾列出所有排隊病人的病歷號,并退出運行。
5:下班——退出運行。
//計算機 小淇在敲代碼 編寫病人看病模擬程序 #include <stdio.h> #include <malloc.h> //鏈隊 typedef struct qnode {int data;struct qnode *next; } QNode; typedef struct {QNode *front,*rear; } QuType; //模仿看病流程 void SeeDoctor() {int sel,flag=1,find,no;QuType *qu;QNode *p,*q;qu=(QuType *)malloc(sizeof(QuType)); qu->front=qu->rear=NULL;while (flag==1) {printf("1:排隊\n2:就診\n3:查看排隊\n4.不再排隊,余下依次就診\n5:下班\n 請選擇: ");scanf("%d",&sel);switch(sel){case 1:printf("請輸入病歷號: ");do{scanf("%d",&no);find=0;p=qu->front;while (p!=NULL && !find){if (p->data==no)find=1;elsep=p->next;}if (find)printf("輸入的病歷號重復,請重新輸入: ");}while (find==1);p=(QNode *)malloc(sizeof(QNode)); p->data=no;p->next=NULL;if (qu->rear==NULL) {qu->front=qu->rear=p;}else{qu->rear->next=p;qu->rear=p; }break;case 2:if (qu->front==NULL) printf("沒有排隊的病人!\n");else {p=qu->front;printf("病人%d就診\n",p->data);if (qu->rear==p) {qu->front=qu->rear=NULL;}elsequ->front=p->next;free(p);}break;case 3:if (qu->front==NULL) printf("沒有排列的病人!\n");else {p=qu->front;printf("排隊病人:");while (p!=NULL){printf("%d ",p->data);p=p->next;}printf("\n");}break;case 4:if (qu->front==NULL) printf("沒有排列的病人!\n");else {p=qu->front;printf("病人按以下順序就診:");while (p!=NULL){printf("%d ",p->data);p=p->next;}printf("\n");}flag=0; break;case 5:if (qu->front!=NULL) printf("請排隊的病人明天就醫!\n");flag=0; break;}}p=qu->front; while (p!=NULL){q = p->next;free(p);p = q;} }//主函數 int main() {printf("計算機 小淇在敲代碼\n");SeeDoctor(); return 0; }總結
以上是生活随笔為你收集整理的编写病人医院看病模拟程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: std::generate和std::g
- 下一篇: radare2