How to insert element into a deque from the back in C++

1 Answer

0 votes
#include <iostream> 
#include <deque> 

void printdq(std::deque <int> dq) { 
    for (auto it = dq.begin(); it != dq.end(); ++it) 
        std::cout << *it << " "; 
    std::cout << '\n'; 
} 

int main() 
{ 
    std::deque<int> dq = { 5, 2, 9, 12, 7, 9, 13, 89 }; 
    
    printdq(dq);
    
    dq.push_back(100); 
    
    printdq(dq);
  
    return 0; 
} 
  
  
  
/*
run:
  
5 2 9 12 7 9 13 89 
5 2 9 12 7 9 13 89 100 
  
*/

 



answered Jul 22, 2020 by avibootz

Related questions

1 answer 197 views
1 answer 175 views
1 answer 192 views
1 answer 174 views
1 answer 255 views
2 answers 220 views
2 answers 226 views
...