Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std ;
- #define M 500
- class _queue
- {
- int arr[M], top, rear;
- public:
- _queue()
- {
- top = rear = -1;
- };
- void push(int a)
- {
- if(rear == M )
- {
- cout <<"overflow\n";
- return ;
- }
- if(top == -1)
- top++;
- rear++ ;
- arr[rear ] = a;
- cout << "Item inserted to queue : " << a << endl ;
- }
- void pop(void )
- {
- if(top > rear || rear == -1)
- {
- cout << "Queue empty\n";
- top = rear = -1;
- return ;
- }
- cout<< "Deleting item : " << arr[top ] << endl;
- top++;
- }
- void front()
- {
- if(top == -1 || top > rear )
- cout << "queue empty" << endl;
- else
- cout << arr[top ] << endl ;
- }
- };
- void input()
- {
- _queue q ;
- int i, j,k ;
- while(1)
- {
- int choice, item ;
- cout <<"Enter choice (0/1)" << endl;
- cout <<"0 - to delete from queue :" << endl;
- cout <<"1 - to insert into queue or " << endl;
- cout <<"2 - to show front :" << endl;
- cin >> choice ;
- if(choice == 1)
- {
- cout <<"Enter item\n";
- cin >> item ;
- q.push(item );
- }
- else if(choice == 0) q.pop();
- else q.front();
- cout <<"\n" << endl;
- }
- }
- int main()
- {
- input();
- /*
- _queue q ;
- q.push(11);
- q.push(12);
- q.push(13);
- q.front();
- q.pop();
- q.pop();
- q.pop();
- q.pop();
- */
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement