A queue is an ordered list in which items may be added only at one end called the “rear” and items may be removed only at the other end called “front”.
Data Structures Interview Questions
Front=-1; Rear=-1;
Program: Implementation of linear queues using arrays.
# include <studio.h>
#include <conio.h>
#include <stdlib.h>
#define maxsize 5
intqueue [maxsize];
int Front=-1;
int Rear=-1;
void Insertion ()
{
intele;
if(Rear== maxsize-1)
{
printf(“Queue is overflow n”);
}
else
{
printf(“Enter an element:”);
sacnf(“%d”,&ele);
Rear=Rear+1;
Queue[Rear]=ele;
if(Front==-1)
{
Front=0;
}
}
}
void deletion ()
{
if(Front==-1)
{
printf(“Queue is under flown”);
}
else
{
printf(“ Deleted element is: %d n”, Queue [Front]);
if (Front==Rear)
{
Front=-1;
Rear=-1;
}
else
{
Front=Front+1;
}
}
}
void display ()
{
inti;
if (Front ==-1)
{
printf(“Queue is under flow n”);
}
else
{
for(i= Front; i<= Rear; i++)
{
prinft(“%5d”,Queue[i]);
}
printf(“n”);
}
}
void main()
{
int choice;
clrscr();
int choice;
printf(“1.INSERTION n”);
printf(“2.DELETION n”);
printf(“3.DISPLAY n”);
printf(“4.EXIT n”);
do
{
printf(“Enter your choice:”);
scanf(“%d”,&choice);
switch (choice)
{
case1: insertion (); break;
case2: deletion (); break;
case3: Display(); break;
case4: (0);
}
}
while (choice <=4)
}
1). Initial State:
2). After inserting element 10
3). After inserting elements 20, 30, 40, 50:
4). Inserting element 60 Queue is over flow
5).After deleting elements 10,20,30,40:
5). After inserting elements 20, 30, 40, 50:
You liked the article?
Like: 14
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.