Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

how to use deque in c++

// CPP Program to implement Deque in STL
#include <deque>
#include <iostream>
  
using namespace std;
  
void showdq(deque<int> g)
{
    deque<int>::iterator it;
    for (it = g.begin(); it != g.end(); ++it)
        cout << '	' << *it;
    cout << '
';
}
  
int main()
{
    deque<int> gquiz;
    gquiz.push_back(10);
    gquiz.push_front(20);
    gquiz.push_back(30);
    gquiz.push_front(15);
    cout << "The deque gquiz is : ";
    showdq(gquiz);
  
    cout << "
gquiz.size() : " << gquiz.size();
    cout << "
gquiz.max_size() : " << gquiz.max_size();
  
    cout << "
gquiz.at(2) : " << gquiz.at(2);
    cout << "
gquiz.front() : " << gquiz.front();
    cout << "
gquiz.back() : " << gquiz.back();
  
    cout << "
gquiz.pop_front() : ";
    gquiz.pop_front();
    showdq(gquiz);
  
    cout << "
gquiz.pop_back() : ";
    gquiz.pop_back();
    showdq(gquiz);
  
    return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #deque
ADD COMMENT
Topic
Name
4+7 =