C program to implement circular queue data structure

Simple C program to implement circular queue data structure

Code:

#include<stdio.h>
#include<conio.h>
int f=0,r=0,q[5],n=5;
void insert(int ele)
{
if(r==n && f==0)
printf("Queue overflow");
else if(r==f && r!=0)
printf("Queue overflow");
else if(r==n && f!=0)
{
r=0;
q[r]=ele;
r++;
printf("%d is inserted",ele);
}
else
{
q[r]=ele;
r++;
printf("%d is inserted",ele);
}
}
int del()
{
if(f==r)
{
printf("Stack underflow");
f=0;
r=0;
}
else if(f==n && r!=0)
{
f=0;
printf("%d is deleted",q[f]);
return(q[f++]);
}
else
{
printf("%d is deleted",q[f]);
return(q[f++]);
}
}
void main()
{
int c,ele;
l:
clrscr();
printf("\nEnter 1 for insert\nEnter 2 for delete");
scanf("%d",&c);
if(c==1)
{
printf("Enter ele");
scanf("%d",&ele);
insert(ele);
}
if(c==2)
{
del();
}
printf("\nEnter 1 for exit\nelse continue");
scanf("%d",&c);
if(c!=1)
goto l;
getch();
}

Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

Java Program to Implement sorting algorithm using TCP on Server application

C++ program to perform data transformation Min-max and Z score Normalization