Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circular queue #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions circularqueue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <stdio.h>
#include<stdlib.h>
#define MAX 6

void enqueue_f(int[],int*,int);
int delqueue_f(int[],int*);
void display_f(int[],int,int);
int main()
{
int Q[5],num,choice,f=1,r=0;
while(1)
{
printf("Choose any one for the following:\n");
printf("1.\tINSERTION\n2.\tDELETION\n3.\tDISPLAY\n4.\tEXIT\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
if(r%MAX+1==f&r!=0)
printf("QUEUE IS FULL!\n");
else
{
printf("Enter the value you want to enter\n");
scanf("%d",&num);
enqueue_f(Q,&r,num);
}
break;
case 2:
if(r==0)
printf("QUEUE IS EMPTY!\n");
else
{
if(f==r)
{
num=delqueue_f(Q,&f);
printf("Deleted value is:%d\n",num);
f=1,r=0; //resetting the pointers
}
else
{
num=delqueue_f(Q,&f);
printf("Delted value is:%d\n",num);
}
}
break;
case 3:
if(r==0)
printf("QUEUE IS EMPTY!\n");
else
display_f(Q,r,f);
break;
case 4:
exit(0);
case 5:
printf("INVALID INPUT\nPlease choose correct option\n");
}
}
return 0;
}

//functions
void enqueue_f(int q[5],int *rear,int temp)
{
*rear=*rear%MAX+1;
q[*rear]=temp;
}
int delqueue_f(int q[5],int *front)
{
int temp;
temp=q[*front];
*front=*front%MAX+1;
return temp;
}
void display_f(int q[5],int rear,int front)
{
int i;
for(i=0;i<5;i=i%MAX+1)
{
printf("%d",q[i]);
}
}