Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #define MAX 50
- using namespace std;
- class queue
- {
- int a[MAX];
- int rear,front;
- public:
- queue()
- {
- rear=0;
- front=0;
- }
- void insert(int x)
- {
- if(rear==MAX)
- {
- cout <<"Queue reached Maximum\n";
- front=rear=0;
- return;
- }
- a[++rear]=x;
- }
- void remove()
- {
- if(front==rear)
- {
- cout <<"Queue is Empty\n\n";
- return;
- }
- cout <<"deleted\n" <<a[++front]<<" \n";
- }
- void display()
- {
- cout << "Queue Size : " << (rear - front);
- for(int i=front+1; i<=rear; i++)
- cout <<a[i]<<endl;
- }
- };
- int main()
- {
- int item;
- queue q;
- while(1)
- {
- cout <<"\n1.insert 2.remove 3.display\n\n";
- cin >> item;
- switch(item)
- {
- case 1:
- cout <<"Enter the elements\n";
- for(int i=1; i<=5; i++)
- {
- cin >> item;
- q.insert(item);
- }
- break;
- case 2:
- q.remove();
- break;
- case 3:
- q.display();
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement