# Include <iostream>
# Define size 10
Using namespace STD;
Typedef int type;
Typedef struct qnode {
Type data;
Qnode * next;
} Qnode, * queue_pp;
Typedef struct {
Queue_pp front;
Queue_pp rear;
Int qlen;
} Linkqueue;
Int initqueue (linkqueue & Q) {// construct an empty queue
Q. Front = Q. Rear = new qnode;
If (! Q. Front) return 0;
Q. Front-> next = NULL;
Q. qlen = 0;
Return 1;
}
Int destroyqueue (linkqueue & Q) {// unqueue
While (Q. Front ){
Q. Rear = Q. Front-> next;
Delete Q. Front;
Q. Front = Q. rear;
}
Return 1;
}
Int insertqueue (linkqueue & Q, Type E) {// insert element e into the new team End Element
Qnode * P;
P = new qnode;
If (! P) return 0;
P-> DATA = E; P-> next = NULL;
Q. Rear-> next = P;
Q. Rear = P;
++ Q. qlen;
Return 1;
}
Int deletequeue (linkqueue & Q, Type E) {// delete a team Header element
If (Q. Front = Q. Rear) return 0;
Qnode * P;
P = Q. Front-> next;
E = p-> data;
Q. Front-> next = p-> next;
If (Q. Rear = P) Q. Rear = Q. Front;
Delete Q. Front;
-- Q. qlen;
Return 1;
}
Int queueexist (linkqueue & Q) {return Q. Front = 0;} // whether the queue exists
Int queueclear (linkqueue & Q) {// empty team
Qnode * E;
E = Q. Front-> next;
Delete Q. Front;
Q. Front = E;
}
Int queueempty (linkqueue & Q) {return Q. Front = Q. Rear;} // The empty queue is true.
Int queuelength (linkqueue q) {cout <q. qlen <Endl;} // Number of queue Elements
Int queueshow (linkqueue & Q) // output queue Element
{
If (queueempty (q) | queueexist (q ))
Cout <"no element in team" <Endl;
Else {
Qnode * P;
P = Q. Front-> next;
While (p ){
Cout <p-> data <"";
P = p-> next ;}
}
}
Int main ()
{
Cout <"□□□□□basic queue operations □□□□" <Endl;
Cout <"□□□□1. Create an empty queue □□□□" <Endl;
Cout <"□□□□2. Insert the queue □□□□□" <Endl;
Cout <"□□□3. Delete the Header element □□□□" <Endl;
Cout <"□□□4. Return queue length □□□□" <Endl;
Cout <"□□□5. Check whether the queue is empty □" <Endl;
Cout <"□□□□6. Clear the queue □□□□□" <Endl;
Cout <"□□□□7. unqueue □□□□□" <Endl;
Cout <"□□□□8. output queue □□□□□" <Endl;
Cout <"□□□0. Exit □□□□□□□" <Endl;
Linkqueue QQ;
Int ch;
Type E;
While (1 ){
Cout <Endl;
Cout <"Enter your choice" <Endl;
Cin> CH;
Switch (CH)
{
Case 1:
Initqueue (qq );
Cout <"the queue has been created" <Endl;
Break;
Case 2:
If (queueexist (qq) break;
Cout <"Your element is :";
Cin> E;
Insertqueue (QQ, e );
Cout <"element in the team :";
Queueshow (qq );
Break;
Case 3:
If (queueexist (qq ))
Break;
Deletequeue (QQ, e );
Cout <"the element you deleted is" <E;
Queueshow (qq );
Break;
Case 4:
Queuelength (qq );
Break;
Case 5:
If (queueempty (qq ))
Cout <"Empty team" <Endl;
Else {
Cout <"the team is not empty" <Endl ;}
Break;
Case 6:
Queueclear (qq );
Break;
Case 7:
Destroyqueue (qq );
Break;
Case 8:
Queueshow (qq );
Break;
Case 0:
Exit (0 );
Break;
Default:
Cout <"input error. Please enter again and select" <Endl;
Break;
}
}
System ("pause ");
Return 1;
}