Answers for "deque stl"

C++
0

deque stl

#include<iostream>
#include<deque>
#include<algorithm>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    deque<int>d;
    d.push_back(50);
    d.push_back(75);
    d.push_front(25);
    d.push_front(10);
    d.push_back(100);
    for(deque<int>::iterator it=d.begin();it!=d.end();it++)
    {
        cout<<*it<<endl;
    }
    cout<<"-----------------------"<<endl;
    d.pop_back();
    d.pop_front();
    for(deque<int>::iterator it=d.begin();it!=d.end();it++)
    {
        cout<<*it<<endl;
    }
    cout<<"-----------------------"<<endl;
    auto it1=d.begin()+1;
    d.insert(it1,5,30);
    for(deque<int>::iterator it=d.begin();it!=d.end();it++)
    {
        cout<<*it<<endl;
    }
    cout<<"-----------------------"<<endl;
    deque<int>d1{10,20,30,40,50};
    d.insert(it1,d1.begin(),d1.end());
    for(deque<int>::iterator it=d.begin();it!=d.end();it++)
    {
        cout<<*it<<endl;
    }
    cout<<"-----------------------"<<endl;
return 0;
}
Posted by: Guest on June-08-2021

Browse Popular Code Answers by Language