0% found this document useful (0 votes)
13 views2 pages

Lab2 Implementation of Queue Using Array

lab2

Uploaded by

ibmcomputer112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Lab2 Implementation of Queue Using Array

lab2

Uploaded by

ibmcomputer112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Implementation of Queue using Array

#include<stdio.h>
#include<conio.h>
#define max 5
int queue[max];
int rear = -1;
int front = 0;
// function for insert element into queue
void insert()
{
int element;
if(rear==max-1)
printf("\nqueue is overflow");
else
{
if(rear = = -1)
printf("\nEnter a value:");
scanf("%d",&element);
rear+=1;
queue[rear]=element;
}
}
// function for delete element from the queue
void delete()
{
int element;
if(rear < front)
printf(" underflow condition\n");
else
{
element=queue[front];
front+=1;
printf("%d is deleted\n",element);
}
}
// function for display all the element of the queue
void display()
{
int i;
if(rear = = -1)
printf("Underflow condition\n");
else
{
for(i=front; i<=rear; i++)
printf("%d\n",queue[i]);
}
}
// Driver function
void main()
{
int ch;
printf("1. insert element\n");
printf("2. delete element\n");
printf("3. display element\n");
printf("4. exit\n");
while(1)
{
printf("Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: insert();
break;
case 2: delete();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("\nWrong key");
}
}
}

You might also like