C program to impement circular queue using array

#include<stdio.h>
//#include<conio.h>
#define MAX 5
void insert(int);
void delete();
void display();
int queue[MAX];
int front=-1,rear=-1;

void insert(int num)
{
if((front==0 && rear==MAX-1)|| (front==rear-1))
printf(“nn Queue is full”);
else

if(front==-1)
{
rear=0;
front=0;
}
else if(rear==MAX-1)
rear=0;
else
rear++;
queue[rear]=num;
}

void delete()
{
int num;
if (front==-1)
printf(“nn Queue is emptyn”);
else
{
num=queue[front];
if(front==rear)
{
front=-1;
rear=-1;
}
else if(front==MAX-1)
front=0;
front++;
printf(“nn item deleted %d”,num);
}
}

void display()
{
int i;
if((front==-1)||(front==rear+1))
printf(“nn Queue is emptyn”);
else
{
printf(“n The front and rear %d %d”,front,rear);
printf(“n The Queue is”);
for(i=front;i<=rear;i++)
printf(“t %d”,queue[i]);
}
}
int main()
{
int ch,num;
printf(“n main menu”);
printf(“n 1.insert”);
printf(“n 2.delete”);
printf(“n 3.Display”);
while(ch!=4)
{
printf(“n Enter your choice n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
printf(“n insert an elementn”);
scanf(“%d”,&num);
insert(num);
break;
case 2:
delete();
break;
case 3:
display();
break;
}
}while(ch!=4);
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io

 

You have Successfully Subscribed!

Open chat