You are on page 1of 3

#include<iostream.h> #include<conio.h> #include<stdio.

h> class CIRCULARQ { int cq[10],n,front,rear; public: CIRCULARQ() { front=rear=-1; n=10; } void insertq(); void deleteq(); void displayq(); }; void CIRCULARQ::insertq() { int val; if(front!=(rear+1)%n) { cout<<"\n ENTER THE NUMBER : "; cin>>val; rear=(rear+1)%n; cq[rear]=val; if(front==-1) front=0; } } void CIRCULARQ::deleteq() { if(front==-1) cout<<"\n CIRCULAR QUEUE EMPTY: \n"; else { cout<<"\n DELETED ELEMENT: "<<cq[front]; if(front==rear) front=rear=-1; else front=(front+1)%n; } } void CIRCULARQ::displayq() { int i; cout<<"\n CIRCULAR QUEUE: "; if(front==-1) cout<<" EMPTY \n"; else if(front<=rear) { for(i=front;i<=rear;i++) cout<<cq[i]<<" "; } else { for(i=front;i<n;i++) cout<<cq[i]<<" ";

} } void main() { CIRCULARQ c; int opt; do { cout<<"\n MENU\n 1.INSERT \n 2.DELETE \n 3.DISPLAY \n"; cin>>opt; switch(opt) { case 1: c.insertq(); c.displayq(); break; case 2: c.deleteq(); c.displayq(); break; case 3: c.displayq(); break; default: cout<<"\n WRONG OPTION \n"; } }while(opt<=3); getch(); } /* OUTPUT MENU 1.INSERT 2.DELETE 3.DISPLAY 1 ENTER THE NUMBER : 1 CIRCULAR QUEUE: 1 MENU 1.INSERT 2.DELETE 3.DISPLAY 1 ENTER THE NUMBER : 2 CIRCULAR QUEUE: 1 2 MENU 1.INSERT 2.DELETE 3.DISPLAY 1 ENTER THE NUMBER : 3 CIRCULAR QUEUE: 1 2 3 MENU 1.INSERT 2.DELETE 3.DISPLAY 1 ENTER THE NUMBER : 4

CIRCULAR QUEUE: 1 2 3 4 MENU 1.INSERT 2.DELETE 3.DISPLAY 2 DELETED ELEMENT: 1 CIRCULAR QUEUE: 2 3 4 MENU 1.INSERT 2.DELETE 3.DISPLAY 2 DELETED ELEMENT: 2 CIRCULAR QUEUE: 3 4 MENU 1.INSERT 2.DELETE 3.DISPLAY 2 DELETED ELEMENT: 3 CIRCULAR QUEUE: 4 MENU 1.INSERT 2.DELETE 3.DISPLAY 2 DELETED ELEMENT: 4 CIRCULAR QUEUE: EMPTY MENU 1.INSERT 2.DELETE 3.DISPLAY 4 WRONG OPTION */

You might also like