0% found this document useful (0 votes)
16 views3 pages

Queue Operations Using Arrays

Uploaded by

shaikofficial66
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)
16 views3 pages

Queue Operations Using Arrays

Uploaded by

shaikofficial66
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/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy