文章目录如何利用简单队列实现完整的程序
程序功能概览一、项目要求二、使用步骤
1.引入库2.读入数据总结完整代码
程序功能概览
一、项目要求 二、使用步骤 1.引入库
代码如下(示例):
#include2.定义结构体//万能库函数
代码如下(示例):
typedef int Status;
typedef struct LNode
{
int data;
char name[20];
struct LNode *next, *pre;
} LNode;
typedef struct
{
LNode *front, *rear;
} Llink;
完整代码#includeusing namespace std; typedef int Status; typedef struct LNode { int data; char name[20]; struct LNode *next, *pre; } LNode; typedef struct { LNode *front, *rear; } Llink; void menu(); Status Init; int main() { int flag = 1, choice, count = 0, find, num, search, count1 = 0; char patient[20]; LNode *p, *q; Llink *s; s = new Llink; s->front = s->rear = NULL; while (flag == 1) { menu(); cin >> choice; switch (choice) { case 1: cout << "请输入病例号和病人姓名(示例:10010 张三)" << endl; do { cin >> num >> patient; find = 0; p = s->front; while (p != NULL && !find) { if (p->data == num) find = 1; else p = p->next; } if (find) cout << "输入不合法,请重新输入:" << endl; } while (find == 1); p = new LNode; p->data = num; strcpy(p->name, patient); p->next = NULL; p->pre = s->rear; if (s->rear == NULL) { s->front = s->rear = p; } else { s->rear->next = p; s->rear = p; } break; case 2: if (s->front == NULL) cout << "没有排队的病人" << endl; else { p = s->front; cout << "病人" << p->data << p->name << "就诊" << endl; if (s->rear == p) { s->front = s->rear = NULL; } else { s->front = p->next; } free(p); } break; case 3: cout << "请输入要查询的病历号" << endl; cin >> search; p = s->front; if (s->front == NULL) cout << "没有人在排队" << endl; else { while (search != p->data) { p = p->next; } do { cout << p->data << p->name << endl; p = p->pre; count1++; } while (p); //掉头发 cout << "前面还有" << count1 - 1 << "人" << endl; } break; case 4: if (s->front == NULL) cout << "没有人在排队" << endl; else { p = s->front; cout << "排队病人" << endl; while (p != NULL) { cout << p->data << p->name << endl; p = p->next; count++; } cout << "共有" << count << "人在排队" << endl; } break; case 5: if (s->front != NULL) cout << "请没看完的病人明天就医" << endl; flag = 0; break; case 6: s = new Llink; s->front = s->rear = NULL; if(s) cout<<"系统初始化成功"< front; while (p != NULL) { q = p->next; free(p); p = q; } return 0; } void menu() { cout << "tt医院就诊系统" << endl; cout << "t>>1.候诊" << endl; cout << "t>>2.就诊" << endl; cout << "t>>3.查看排队情况" << endl; cout << "t>>4.查看看诊" << endl; cout << "t>>5.下班" << endl; cout << "t>>6.上班" << endl; cout << "t>>7.统计" << endl; cout << "t>>请输入您要执行的操作:" << endl; system("pause"); system("cls"); }



