# Include
Using namespace std; // node class template
Struct QNode {T data; QNode * next;}; // queue class template
Struct LinkList {QNode
* Front; QNode
* Rear; size_t size ;}; // construct an empty queue template
Void InitQueue (LinkList
& Que) {que. front = (QNode
*) Malloc (sizeof (QNode
); If (! Que. front) exit (0); que. size = 0; que. rear = que. front; que. rear-> next = 0;} // destroy the queue template
Void DestroyQueue (LinkList
& Que) {QNode
* P = que. front-> next; free (que. front); while (p! = 0) {que. front = p-> next; free (p); p = que. front ;}// clear the queue template
Void ClearQueue (LinkList
& Que) {QNode
* P = que. front-> next; while (p! = 0) {que. rear = p-> next; free (p); p = que. rear;} que. rear = que. front; que. front-> next = 0; que. size = 0;} // return the queue length template
Int QueueLength (LinkList
& Que) {return que. size;} // return the first element template of the queue.
T GetHead (LinkList
& Que) {return que. front-> next-> data;} // element queue template
Void EnQueue (LinkList
& Que, T) {QNode
* P = (QNode
*) Malloc (sizeof (QNode
); If (! P) exit (0); p-> data = t; p-> next = 0; que. rear-> next = p; que. rear = p; que. size ++;} // element team-out template
Bool DeQueue (LinkList
& Que, T & t) {if (que. size = 0) return false; QNode
* P = que. front-> next; que. front-> next = p-> next; que. size --; t = p-> data; free (p); return true;} // call the visit function template from the first to the last element traversal.
Void VisitQueue (LinkList
& Que, void (* visit) (T & t) {QNode
* P = que. front-> next; while (p! = 0) {(* visit) (p-> data); p = p-> next ;}// test the function template.
Void Print (T & t) {cout <
Void AddOne (T & t) {t ++;} int main () {// create an empty queue LinkList
Queue; // initialization queue InitQueue (queue); // element queue EnQueue (queue, 1); EnQueue (queue, 2); EnQueue (queue, 3); EnQueue (queue, 4); // return the length of the queue cout <"Queue Length:" <
); // Return the first element of the queue cout <"first element of the queue:" <
); // Output all the elements VisitQueue (queue, Print
); // Clear the queue ClearQueue (queue); // destroy the queue DestroyQueue (queue );}