queue stl code example
Example 1: stl queue
Functions used here:
q.size() = Returns the size of queue.
q.push() = It is used to insert elements to the queue.
q.pop() = To pop out the value from the queue.
q.front() = Returns the front element of the array.
q.back() = Returns the back element of the array.
Example 2: queue stl
#include <iostream>
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
queue<int>q;
q.push(10);
q.push(5);
q.push(15);
while(!q.empty())
{
cout<<q.front()<<" ";
q.pop();
}
cout<<endl;
cout<<"_------------------------"<<endl;
q.push(10);
q.push(5);
q.push(15);
queue<int>q2;
q2.push(100);
q2.push(200);
q2.push(300);
q2.push(400);
q.swap(q2);
while(!q.empty())
{
cout<<q.front()<<" ";
q.pop();
}
return 0;
}