Write code in C for Linear Queue through Array?
Fill In The Blank
Views 537
Answer:
#include #include # define MAXSIZE 200 int queue[MAXSIZE]; int front=-1, rear=-1; //index pointing to the top of stack void main() { void enqueue(int); int dequeue(); int will=1,i,num,ch; while(will ==1) { printf("MAIN MENU: 1. Enqueue 2.Dequeue 3. Check Queue Full 4. Check Queue Empty "); Scanf ("%d", &ch); switch(ch) { case 1: printf("Enter the data to add... "); scanf("%d", &num); enqueue(num); break; case 2: num=dequeue(); if(num==-1) printf("Queue is empty");\ else printf("Value returned from pop function is %d ",num); break; case 3 : isFull(); break; case 4 : isEmpty(); break; default: printf ("Invalid Choice . "); } printf("Do you want to do more operations on Stack ( 1 for yes, any other key to exit) "); scanf("%d" , &will); } //end of outer while } //end of main void enqueue (int elem) { if(isfull()) { printf("QUEUE FULL"); return; } else{ if(front==-1) front=rear=0; else rear++; queue[rear]=elem; } } int dequeue() { int elem; if(isEmpty()) { return -1; } else { elem=queue[front]; if (front==rear) front=rear=-1; else front++; } return(elem); } int isFull() { if(rear==MAXSIZE-1) return 0; else return 1; } int isEmpty() { if((front==-1) && (front==rear)) return 0; else return 1; }
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Data Structure, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.