#include struct stack { int obj[6] = {0, 0, 0, 0, 0, 0}; int next = 0; int out[6] = {0, 0, 0, 0, 0, 0}; int out_next = 0; }; void out (stack s) { std::cout << "{ "; for (int i = 0; i < s.next; i++) std::cout << s.obj[i] << " "; std::cout << "// "; for (int i = 0; i < s.out_next; i++) std::cout << s.out[i] << " "; std::cout << "}" << std::endl; } void loop (stack s, int next) { if (s.out_next == 6) { for (int i = 0; i < s.out_next; i++) std::cout << s.out[i] << " "; std::cout << std::endl; return; } if (next < 7) { stack sn = stack(s); sn.obj[sn.next] = next; sn.next++; // std::cout << "[DBUG] way IN" << std::endl; // std::cout << "[DBUG][RA]" << s.out_next << std::endl; // std::cout << "[DBUG][XM]"; out(sn); loop(sn, next+1); } if (s.next != 0) { stack sb = stack(s); sb.out[sb.out_next] = sb.obj[sb.next-1]; sb.obj[sb.next-1] = 0; sb.next--; sb.out_next++; // std::cout << "[DBUG] way OUT" << std::endl; // std::cout << "[DBUG][RA]" << s.out_next << std::endl; // std::cout << "[DBUG][XM]"; out(sb); loop(sb, next); } } int main () { loop (stack(), 1); std::cout << "over" << std::endl; return 0; }