# Include <stdio. h> // blockchain queue Storage Structure
# Include <stdlib. h>
# Define overflow-2
Typedef int qelemtype;
Typedef struct qnode {// No qnode is added here. The error is reported ??? Why ???
Qelemtype data;
Struct qnode * next;
} Qnode, * queueptr;
Typedef struct {
Queueptr front;
Queueptr rear;
} Linkqueue;
Void initqueue (linkqueue * q)
{// Construct an empty queue Q
Q-> front = Q-> rear = (queueptr) malloc (sizeof (qnode ));
If (! Q-> front) Exit (overflow );
Q-> front-> next = NULL;
Printf ("the queue is successfully constructed.../N ");
}
Void destroyqueue (linkqueue * q)
{// Destroy the queue
While (Q-> front)
{
Q-> rear = Q-> front-> next;
Free (Q-> front );
Q-> front = Q-> rear;
}
Printf ("the queue is destroyed successfully !!! /N ");
Exit (0 );
}
Void enqueue (linkqueue * q, qelemtype E)
{// Insert a new team-end element whose Element E is Q
Queueptr P;
Printf ("OK now which number do you want input/N ");
Scanf ("% d", & E );
P = (queueptr) malloc (sizeof (qnode ));
If (! P) Exit (overflow );
P-> DATA = E;
P-> next = NULL;
Q-> rear-> next = P;
Q-> rear = P;
Printf ("successfully inserted element/N ");
}
Void dequeue (linkqueue * q, qelemtype E)
{// If the queue is not empty, delete the queue Header element of Q and use e to return its value.
Queueptr P;
If (Q-> front = Q-> rear) {printf ("the queue is empty !!! /N cannot be deleted "); exit (0 );}
P = Q-> front-> next;
E = p-> data;
Q-> front-> next = p-> next;
If (Q-> rear = P) q-> rear = Q-> front;
Free (P );
Printf ("deleted successfully! /N ");
}
Void printqueue (linkqueue * q)
{
If (Q-> front = Q-> rear) {printf ("sorry the queue is empty"); exit (0 );}
While (Q-> front! = Q-> rear)
{
Printf ("% d", Q-> front-> next-> data );
Q-> front = Q-> front-> next;
}
Printf ("/nprint is over/N ");
}
Int main ()
{
Linkqueue Q;
Qelemtype E;
Initqueue (& Q );
Int I;
Printf ("Please put you num what you want to do:/N1: destroy the queue/N2: enqueue/N3: dequeue/N4: printqueue/N ");
Scanf ("% d", & I );
While (I)
{
Switch (I)
{
Case 1: destroyqueue (& Q); break; // destroyqueue (linkqueue * q)
Case 2: enqueue (& Q, e); break;
Case 3: dequeue (& Q, e); break;
Case 4: printqueue (& Q); break;
}
Printf ("You can choose again for/N1: Destroy/N2: enqueue/N3: dequeue/N4: printqueue/N ");
Scanf ("% d", & I );
}
Return 0;
}