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

This contain the circular queue operation. [ Inserting an element and deletion of element] #54

Closed
eshwarprasad opened this issue Oct 4, 2016 · 0 comments

Comments

@eshwarprasad
Copy link

include<stdio.h>

include<stdlib.h>

int ch,i,item,f=0,r=0,q[5],max=5,c=0;
void insert();
void Delete();
void display();
void main()
{
for(;;)
{
printf("\n\tMENU\n1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT\n");
printf("Enter your Choice\n");
scanf("%d", &ch);
switch(ch)
{
case 1: insert();
display();
break;
case 2: Delete();
display();
break;
case 3: display();
break;
case 4: exit(0);

         default: printf("Invalid Input\n");
    }
}

}
void insert()
{
if(f==r && c==max)
{
printf("Insertion not possible, due to overflow\n");
}
else
{
printf("Enter the element to be inserted\n");
scanf("%d", &item);
q[r]=item;
r=(r+1)%max;
c++;
}
}
void Delete()
{
if(f==r && c==0)
{
printf("Deletion is not possible, due to underflow\n");
}
else
{
printf("The item deleted is %d\n",q[f]);
f=(f+1)%max;
c--;
}
}
void display()
{
printf("The circular queue is \n");
for(i=f;i<c+f;i++)
{
printf("%d",q[i]);

 }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant