0% found this document useful (0 votes)
6 views4 pages

QUEUEUSARRAY

Uploaded by

arjunrarjun99
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)
6 views4 pages

QUEUEUSARRAY

Uploaded by

arjunrarjun99
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/ 4

//QUEUE USING ARRAY

// Online C compiler to run C program online


#include <stdio.h>
#include<stdlib.h>
void insert();
void delete();
void dispaly();
int queue[50],size,rear=-1,front=-1;
int main()
{
int choice;
printf("enter the size of queue");
scanf("%d",&size);
while(1)
{
printf("1.insert\n2.delete\n3.dispaly\n4.exit\n");
printf("enter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("\nwrong choice\n");

}
}
}
void insert()
{
int item;
if(rear == size-1)
{
printf("queue overflow\n");

}
else{
printf("\n enter the value to insert\n");
scanf("%d",&item);
if(rear == -1)
{
front++;
}
rear++;
queue[rear] = item;
}

}
void delete()
{
if(front == -1)
{
printf("queue underflow");
}
else
{
printf("\n deleted value is %d\n\n",queue[front]);
front++;
}
}
void display()
{
int i;
if(front==-1)
{
printf("queue is empty");
}
else
{
for(i=front;i<=rear;i++)
{
printf("\n the elements in queue are%d\n\n",queue[i]);
}
}
}

You might also like