12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
using std::cin, std::cout, std::endl, std::flush, std::setw;
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<size_t, size_t>;
stack<stack_item> return_stack;
return_stack.push({1, 0});
while (!return_stack.empty())
{
auto [n, depth] = return_stack.top();
return_stack.pop();
stack<stack_item> queue;
// BEGIN unmodified code
cout
<< setw(depth) << "" << n << endl;
if (depth >= max_recursion_depth)
continue;
for (size_t i = 0; i < fun_count - 1; i++)
{
queue.push({(n + i) % fun_count + 1, depth + 1});
}
|
>
>
>
<
|
>
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
using std::cin, std::cout, std::endl, std::flush, std::setw;
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<size_t, size_t>;
stack<stack_item> return_stack;
return_stack.push({1, 0});
while (!return_stack.empty())
{
auto [n, depth] = return_stack.top();
return_stack.pop();
stack<stack_item> queue;
// BEGIN unmodified code
cout << setw(depth) << "" << n << endl;
if (depth >= max_recursion_depth)
continue;
for (size_t i = 0; i < fun_count - 1; i++)
{
queue.push({(n + i) % fun_count + 1, depth + 1});
}
|