Index: src/main.cxx ================================================================== --- src/main.cxx +++ src/main.cxx @@ -14,15 +14,18 @@ using std::stack, std::tuple; void f_rec(const size_t fun_count, const size_t max_recursion_depth, const size_t n = 1, const size_t depth = 0) { cout << setw(depth) << "" << n << endl; + if (depth >= max_recursion_depth) return; for (size_t i = 0; i < fun_count - 1; i++) + { f_rec(fun_count, max_recursion_depth, (n + i) % fun_count + 1, depth + 1); + } } void f_iter(const size_t fun_count, const size_t max_recursion_depth) { using stack_item = tuple; @@ -36,12 +39,12 @@ return_stack.pop(); stack queue; // BEGIN unmodified code - cout - << setw(depth) << "" << n << endl; + cout << setw(depth) << "" << n << endl; + if (depth >= max_recursion_depth) continue; for (size_t i = 0; i < fun_count - 1; i++) {