voidenqueue(int data) {// Creating a new queue nodestruct Node *newNode; newNode = (struct Node *)malloc(sizeof(struct Node));newNode -> data = data;// If this node is the first node to be insertedif (front ==NULL) { front = rear = newNode; }// If other nodes are already presentelse {rear -> next = newNode; rear = newNode; }}
Dequeue Operation :
intdequeue() {// If queue is already emptyif (front ==NULL) {printf("Queue underflow\n");return-1; }else {// Pointers for node & data to be deletedstruct Node *toDelete = front;int deletedData =front -> data; front =front -> next;free(toDelete);return deletedData; }}
Display Operation :
voiddisplay() {// If queue is emptyif (front ==NULL) {printf("Queue is empty\n");return; }struct Node *ptr = front;while (ptr !=NULL) {printf("%d\t",ptr -> data); ptr =ptr -> next; }printf("\n");}