Queue Program in C++
Advertisements
Queue Program in C++
Queue Program in C++
#include<iostream.h> #include<conio.h> void insert(); void del(); void display(); struct circ { int cqueue[5]; }; struct circ cque; int rear=0,front=-1; void main() { while(1) { int num; clrscr(); cout<<"1.Insertion\n2.Deletion\n3.Display\n0.Exit\n"; cout<<"\n\nSelect Option : "; cin>>num; switch(num) { case 1: insert(); break; case 2: del(); break; case 3: display(); break; case 0: exit(0); break; default: cout<<"\n\n Invalid Option "; } getch(); } } void insert() { int item; cout<<"Element : "; cin>>item; if(front==(rear+1)%3) { cout<<"Queue is Full"; return; } if(front==-1) { rear=front=0; } else { rear=(rear+1)%3; } cque.cqueue[rear]=item; cout<<"Successfully Insert"; } void del() { int num; if(front==-1) { cout<<"Queue Empty"; return; } else { num=cque.cqueue[front]; cout<<"Deleted item : "<<num; } if(front==rear) { front=-1; } else front=(front+1)%3; } void display() { int i; if(front==-1) { cout<<"Queue Empty"; return; } else { cout<<"\n\nItems : "; for(i=front;i<=rear;i++) { cout<<" "<<cque.cqueue[i]; } } }
Google Advertisment