Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<stdio.h>
- #include<conio.h>
- #define MAXSIZE 3
- class queue
- {
- int queue[MAXSIZE],front,rear;
- public:queue()
- {
- front=rear=-1;
- }
- void insert(void);
- void del(void);
- void display(void);
- };
- void queue::insert(void)
- {
- int item;
- if(rear==MAXSIZE-1)
- {
- cout<<"Queue Overflow"<<endl;
- return;
- }
- if(front==-1)
- front=rear=0;
- else
- rear=rear+1;
- cout<<"Enter the item to be inserted"<<endl;
- cin>>item;
- queue[rear]=item;
- display();
- }
- void queue::del(void)
- {
- int item;
- if(front==-1)
- {
- cout<<"Queue underflow"<<endl;
- return;
- }
- item=queue[front];
- cout<<"\nThe element deleted is"<<item<<endl;
- if(front==rear)
- front=rear-1;
- else
- front=front+1;
- display();
- }
- void queue::display(void)
- {
- if(front==-1)
- cout<<"Queue is empty"<<endl;
- else
- {
- for(int i=front;i<=rear;i++)
- cout<<queue[i]<<"\t";
- }
- }
- int main()
- {
- clrscr();
- int choice;
- char ch;
- queue obj;
- do
- {
- cout<<"\nMAIN MENU";
- cout<<"\n1.Insert\n2.Delete\n3.Display";
- cout<<"Enter your choice";
- cin>>choice;
- switch(choice)
- {
- case 1: obj.insert();
- break;
- case 2: obj.del();
- break;
- case 3: obj.display();
- break;
- default: cout<<"\nInvalid choice"<<endl;
- }
- cout<<"Do you wish to continue"<<endl;
- fflush(stdin);
- cin>>ch;
- }
- while(ch=='y'||'Y');
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement