#include<stdio.h> #include<conio.h> int arr[50]; int max=5,front=-1,rear=-1; void insert(){ int item; if((front==0&&rear==max-1)||(front==rear+1)){ printf("Overflow\n"); }else{ if(front==-1){ front++; rear++; }else if(rear==max-1){ rear=0; }else{ rear++; } printf("Enter item: "); scanf("%d",&item); arr[rear]=item; } } void delet(){ if(front==-1){ printf("Underflow\n"); }else{ if(front==rear){ front=-1;rear=-1; } else if(front==max-1){ front=0; } else{ front++; } } } void display(){ int temp,i; if(front==-1){ printf("Underflow\n"); }else if(front<rear){ temp=front; while(temp<=rear){ printf("%d, ",arr[temp]); temp++; } }else if(front>rear){ for(i=front;i<max;i++){ printf("%d, ",arr[i]); } for(i=0;i<=rear;i++){ printf("%d, ",arr[i]); } }else{ printf("%d",arr[front]); } printf("\n"); } int main(){ int ch=1; clrscr(); printf("1.Insertion \n2.Deletion \n3. Display \n0 for Exit \n"); while(ch!=0){ printf("Enter your choice: "); scanf("%d",&ch); switch(ch){ case 1: insert(); break; case 2: delet(); break; case 3: display(); break; } } getch(); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter