Queue chain implementation and queue chain implementation
Queue chain implementation:
In this queue: r is low, f is the top
// Queue (chained) # include <iostream> using namespace std; typedef int DataType; struct QNode {DataType data; struct QNode * link;}; typestrudef CT QNode * PNode; // if r is low, the top is struct LinkQueue {PNode f; PNode r ;}; typedef struct LinkQueue * PLinkQueue; PLinkQueue createEmptyQueue () {PLinkQueue plqueue = (PLinkQueue) malloc (sizeof (struct LinkQueue); if (plqueue! = NULL) {plqueue-> f = NULL; plqueue-> r = NULL;} else printf ("Out of space \ n"); return plqueue ;} int isEmptyQueue (PLinkQueue plqueue) {return (plqueue-> f = NULL);} void enQueue (PLinkQueue plqueue, DataType x) {PNode p = (PNode) malloc (sizeof (struct QNode); if (p! = NULL) {p-> data = x; p-> link = NULL; if (plqueue-> f = NULL) plqueue-> f = p; else plqueue-> r-> link = p; plqueue-> r = p;} else printf ("Out of space \ n");} void deQueue (PLinkQueue plqueue) {PNode p = (PNode) malloc (sizeof (struct QNode); if (plqueue-> f = NULL) printf ("Empty Queue \ n "); else {p = plqueue-> f; plqueue-> f = p-> link; free (p) ;}} DataType getFront (PLinkQueue plqueue) {if (plqueue-> f = NULL) printf ("Empty Queue \ n"); else return (plqueue-> f-> data);} int main () {PLinkQueue lqueue = createEmptyQueue (); cout <"Create an nelement queue \ n input n" <endl; int n, t; cin> n; t = n; while (n) {int data; cin> data; enQueue (lqueue, data); n --;} cout <"take the team header and leave the team" <endl; while (t) {cout <getFront (lqueue) <"; deQueue (lqueue); t --;} cout <endl; system (" pause "); return 0 ;}