How to resize deque in C++

2 Answers

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 }; 
    
    printdq(dq);
    
    dq.resize(10); 
    
    printdq(dq);
  
    return 0; 
} 
  
  
  
/*
run:
  
5 2 9 12 7 
5 2 9 12 7 0 0 0 0 0 
  
*/

 



answered Jul 22, 2020 by avibootz
edited Jul 22, 2020 by avibootz
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.resize(3); 
    
    printdq(dq);
  
    return 0; 
} 
  
  
  
/*
run:
  
5 2 9 12 7 9 13 89 
5 2 9 
  
*/

 



answered Jul 22, 2020 by avibootz
edited Jul 22, 2020 by avibootz

Related questions

1 answer 224 views
4 answers 131 views
131 views asked Oct 23, 2025 by avibootz
3 answers 411 views
411 views asked Dec 9, 2020 by avibootz
1 answer 238 views
4 answers 591 views
2 answers 190 views
190 views asked May 4, 2018 by avibootz
...