Answers for "queues using stl"

C++
1

restting a queue stl

// To clear the queue Q defined as "queue<int> Q"
Q = queue<int>();
Posted by: Guest on May-29-2020
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