C Saved Program: ferrous-city

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdio.h>
void insert(int);
void delet();
//int isempty();
int a[100],front=-1,rear=-1;
int main()
{ int x,i,n,ex=0;
    do{
    printf("\nenter the operation you want to perform");
    printf("\n1-insert\n2-delete\n3-display\n4-exit\n");
    scanf("%d",&n);
    switch(n)
    { case 1: printf("eter the element to be inserted  ");
              scanf("%d",&x);
              insert(x);
              break;
       case 2: delet();
               break;
       case 4: ex=1;
    }
    

        for(i=front;i<=rear;i++)
        {
          printf("%d ",a[i]);          
         }
    
    }while(ex!=1);
    return 0;
}


void insert(int y)
{ if(front==-1)
   { front++;
     rear++;
     a[rear]=y;
   }
   else if(front==0 && rear==0)
   { a[rear]=y;
     rear++;
   }
   else
   { rear++;
     a[rear]=y;
   }
   return;
}

void delet()
{ if(front==-1)
  { printf("queue is empty");}
  else if(front==0 && rear==0)
  { front=-1;
    rear=-1;
  }
  else
  { front++;}
  return;
  
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs