/* 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 ();
}