//Circular Queue in C language
#include<stdio.h>
#define MAX 5
int queue[MAX];
int front=-1;
int rear=-1;
insert()
{
int i;
if((rear==MAX-1 && front==0) || (front==rear+1))
{
printf("\nQueue is FUll");
}
else
{
printf("\nEnter an element:: ");
scanf("%d",&i);
if(front==-1)
{
front=0;
}
if(rear==MAX-1)
{
rear=0;
}else
{
queue[++rear]=i;
}
}
}
delete()
{
if(front==-1)
{
printf("Queue is empty");
}
else
{
printf("%d has deleted",queue[front]);
if(front==rear)
{
front=rear=-1;
}else
{
if(front==MAX-1)
{
front=0;
}else
{
front++;
}
}
}
}
int main()
{
int ch,f=0;
//clrscr();//Optional
while(f<=1)
{
printf("\n1. INSERT VALUE\n2. DELETE VALUE\n4. EXIT");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
//getch(); //Optional
break;
case 2:
delete();
//getch();//Optional
break;
case 3:
//clear();
//getch();//Optional
break;
case 4:
//exit();//Optional
default:
printf("\nWrong Input");
}
}
}
#include<stdio.h>
#define MAX 5
int queue[MAX];
int front=-1;
int rear=-1;
insert()
{
int i;
if((rear==MAX-1 && front==0) || (front==rear+1))
{
printf("\nQueue is FUll");
}
else
{
printf("\nEnter an element:: ");
scanf("%d",&i);
if(front==-1)
{
front=0;
}
if(rear==MAX-1)
{
rear=0;
}else
{
queue[++rear]=i;
}
}
}
delete()
{
if(front==-1)
{
printf("Queue is empty");
}
else
{
printf("%d has deleted",queue[front]);
if(front==rear)
{
front=rear=-1;
}else
{
if(front==MAX-1)
{
front=0;
}else
{
front++;
}
}
}
}
int main()
{
int ch,f=0;
//clrscr();//Optional
while(f<=1)
{
printf("\n1. INSERT VALUE\n2. DELETE VALUE\n4. EXIT");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
//getch(); //Optional
break;
case 2:
delete();
//getch();//Optional
break;
case 3:
//clear();
//getch();//Optional
break;
case 4:
//exit();//Optional
default:
printf("\nWrong Input");
}
}
}
Comments
Post a Comment