vaibhava96 vaibhava96 - 3 months ago 11
C++ Question

looping through a deque recursively c++

I am trying to create a function that takes in a deque of integers as a parameter, loops through each element one by one, and returns the deque recursively. I have found a few previous posts on StackOverflow that do something similar, but I am unable to understand what is happening in their answers. I am relatively new to C++. Help is greatly appreciated.

Answer

it should be something like this

deque <int> x;
void Calc (deque <int> d){
    if (d.empty()) return;
    x.push_back(d.front());
    d.pop_front();
    Calc(d);
}
Comments