Patient Simulation Program

Source: Internet
Author: User

/* File name: exp3-6.cpp */
# Include <stdio. h>
# Include <malloc. h>
Typedef struct qnode
{
Int data;
Struct qnode * next;
} Qnode;/* node type of the blockchain node */
Typedef struct
{
Qnode * front, * rear;
} Qutype;/* Team type */
Void seedoctor ()
{
Int Sel, flag = 1, find, no;
Qutype * qu;
Qnode * P;
Qu = (qutype *) malloc (sizeof (qutype);/* Create an empty queue */
Qu-> front = qu-> rear = NULL;
While (flag = 1)/* loop execution */
{
Printf ("1: queuing 2: Seeing A Doctor 3: checking the queue 4. No longer queuing, followed by seeing a doctor 5: After work please select :");
Scanf ("% d", & SEL );
Switch (SEL)
{
Case 1: printf ("> enter the medical record number :");
Do
{
Scanf ("% d", & No );
Find = 0;
P = qu-> front;
While (P! = NULL &&! Find)
{
If (p-> DATA = No)
Find = 1;
Else
P = p-> next;
}
If (FIND)
Printf ("> the input medical record number is repeated and re-input :");
} While (find = 1 );
P = (qnode *) malloc (sizeof (qnode);/* Create a node */
P-> DATA = no; P-> next = NULL;
If (qu-> rear = NULL)/* The first patient queues */
{
Qu-> front = qu-> rear = P;
}
Else
{
Qu-> rear-> next = P; qu-> rear = P;/* queue * P nodes */
}
Break;
Case 2: If (qu-> front = NULL)/* empty Team */
Printf ("> no patient in queue! \ N ");
Else/* the team is not empty */
{
P = qu-> front;
Printf ("> patient % d visiting \ n", p-> data );
If (qu-> rear = P)/* only one patient queues */
{
Qu-> front = qu-> rear = NULL;
}
Else
Qu-> front = p-> next;
Free (P );
}
Break;
Case 3: If (qu-> front = NULL)/* empty Team */
Printf ("> no patient is listed! \ N ");
Else/* the team is not empty */
{
P = qu-> front;
Printf ("> queuing patients :");
While (P! = NULL)
{
Printf ("% d", p-> data );
P = p-> next;
}
Printf ("\ n ");
}
Break;
Case 4: If (qu-> front = NULL)/* empty Team */
Printf ("> no patient is listed! \ N ");
Else/* the team is not empty */
{
P = qu-> front;
Printf ("> see patients in the following sequence :");
While (P! = NULL)
{
Printf ("% d", p-> data );
P = p-> next;
}
Printf ("\ n ");
}
Flag = 0;/* exit */
Break;
Case 5: If (qu-> front! = NULL)/* the team is not empty */
Printf ("> Please wait for the patient to receive medical treatment tomorrow! \ N ");
Flag = 0;/* exit */
Break;
}
}
}
Void main ()
{
Seedoctor ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.