#include <stdio.h> #include <conio.h> #include <stdlib.h> int queue[5]; int front=-1; int rear=-1; void insert() { int item; printf("Enter Data : "); scanf("%d",&item); if(front==-1 && rear==-1) { front++; rear++; queue[rear]=item; } else if(rear==4) { printf("OverFlow"); } else { rear++; queue[rear]=item; } } void delete() { if(front==-1 && rear==-1)printf("UnderFlow"); else if(front==rear) { front=-1; rear=-1; } else { rear--; } } void display() { if(front==-1 && rear==-1) { printf("UnderFlow"); } else if(front==rear) { printf("%d",queue[rear]); } else { int temp=front; while(temp!=rear) { printf("%d ",queue[temp]); temp++; } printf("%d",queue[temp]); } } int isEmpty() { if(front==-1 && rear==-1) return 1; else return 0; } int isFull() { if(rear==4)return 1; else return 0; } void main() { while(1) { int ch; clrscr(); printf("\n1. Insert"); printf("\n2. Delete"); printf("\n3. Display"); printf("\n4. UnderFlow"); printf("\n5. OverFlow"); printf("\n6. EXIT"); printf("\nEnter Your Choice : "); scanf("%d",&ch); switch(ch) { case 1: insert(); break; case 2 : delete(); break; case 3 : display(); break; case 4 : if(isEmpty()) printf("\nUnderFlow"); else printf("\nNo UnderFlow"); break; case 5 : if(isFull())printf("\nOverflow"); else printf("\nNo OverFlow"); break; case 6 : exit(0); break; default: printf("\nInvalid Choice"); } getch(); } }
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