How to declare and initial 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);
  
    return 0; 
} 
  
  
  
/*
run:
  
5 2 9 12 7 
  
*/

 



answered Jul 22, 2020 by avibootz
0 votes
#include <iostream> 
#include <deque> 

void printdq(std::deque <char> dq) { 
    for (auto it = dq.begin(); it != dq.end(); ++it) 
        std::cout << *it << " "; 
    std::cout << '\n'; 
}  
    
int main() 
{ 
    std::deque<char> dq = { 'a', 'b', 'c', 'd', 'e' }; 

    printdq(dq);
  
    return 0; 
} 
  
  
  
/*
run:
  
a b c d e 
  
*/

 



answered Jul 22, 2020 by avibootz

Related questions

1 answer 100 views
1 answer 174 views
1 answer 198 views
2 answers 179 views
1 answer 175 views
1 answer 205 views
...