Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #define q_s 3
- #define r rear
- #define f front
- int r,f;
- int queue[q_s];
- void Insertion(int ele){
- if( (r+1) % q_s == f ) {
- printf("\nQueue is full");
- return;
- }
- else if (r == -1 && f == -1){
- r = f = 0;
- }
- else r =(r+1) % q_s;
- queue[r] = ele;
- }
- void Deletion(){
- if(r==-1) printf("\nQueue is already empty");
- else if (r == f){
- queue[f]=0;
- r = f = -1;
- }
- else queue[f++] = 0;
- }
- void Print(){
- if(r == -1) {
- printf("\nQueue is empty");
- return;
- }
- else{
- int i;
- for( i=f ; i != r ; i = (i+1)%q_s)
- printf("%d ",queue[i]);
- printf("%d ",queue[i]);
- }
- }
- int main()
- {
- r = f = -1;
- int key,choice,element;
- while(1){
- printf("\n1 for insertion \n2 for deletion\nAny key to just print the queue\n");
- scanf("%d",&choice);
- if(choice==1){
- printf("\nEnter the element ");
- scanf("%d",&element);
- Insertion(element);
- }
- else if(choice==2){
- Deletion();
- }
- else Print();
- printf("\n1 - for repeat and any key to exit ");
- scanf("%d",&key);
- if(key!=1)break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment