0% found this document useful (0 votes)
6 views

Queue Operations Using Arrays

Uploaded by

shaikofficial66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Queue Operations Using Arrays

Uploaded by

shaikofficial66
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Write a program to implement Queue operations using an array

#include<stdio.h>
#define MAXSIZE 5
void insertque(int);
void deleteque();
void display();
int queue[MAXSIZE], front = -1, rear = -1;
void main()
{
int choice,value;
clrscr();
while(choice!=4)
{
printf("\nEnter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("Enter the value to insert: ");
scanf("%d",&value);
insertque(value);
break;
case 2: deleteque();
break;
case 3: display();
break;
case 4: exit(0);
break;
default: printf("\nInvalid choice");
break;
}
}
}

void insertque(int value)


{
if(rear == MAXSIZE-1)
{
printf("\nOverflow,Insertion is not possible!");
}
else
{
if(front == -1 && rear == -1)
{
front=rear=0;
}
else
{
rear++;
}
queue[rear]=value;
printf("\nElement inserted!");
}
}
void deleteque()
{
if(front==-1 && rear==-1)
{
printf("\nUnderflow,Deletion is not possible!");
}
else
{
if(front==rear)
{
printf("\nDeleted element is:%d",queue[front]);
front = rear = -1;
}
else
{
printf("\nDeleted element is:%d",queue[front]);
front++;
}
}
}
void display()
{
if(front==-1 && rear==-1)
{
printf("\nQueue is empty!");
}
else
{
int i;
printf("\nQueue elements are:\n");
for(i=front; i<=rear; i++)
{
printf("%d\t",queue[i]);
}
}
}

You might also like