Answers for "stl queue"

C++
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.
Posted by: Guest on January-05-2021
0

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;
}
Posted by: Guest on June-06-2021

Browse Popular Code Answers by Language