queue stl

Solutions on MaxInterview for queue stl by the best coders in the world

showing results for - "queue stl"
Tom
12 May 2018
1Functions used here:
2   q.size() = Returns the size of queue.
3   q.push() = It is used to insert elements to the queue.
4   q.pop() = To pop out the value from the queue.
5   q.front() = Returns the front element of the array.
6   q.back() = Returns the back element of the array.
Abigail
07 May 2018
1#include <iostream>
2#include<queue>
3#include<algorithm>
4
5using namespace std;
6
7int main()
8{
9    queue<int>q;
10    q.push(10);
11    q.push(5);
12    q.push(15);
13    while(!q.empty())
14    {
15        cout<<q.front()<<" ";
16        q.pop();
17    }
18    cout<<endl;
19    cout<<"_------------------------"<<endl;
20    q.push(10);
21    q.push(5);
22    q.push(15);
23    queue<int>q2;
24    q2.push(100);
25    q2.push(200);
26    q2.push(300);
27    q2.push(400);
28    q.swap(q2);
29    while(!q.empty())
30    {
31        cout<<q.front()<<" ";
32        q.pop();
33    }
34
35    return 0;
36}
37