-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (52 loc) · 1.51 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
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
53
54
55
56
57
58
59
60
61
62
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include "vector"
using namespace std;
#define N 5
void print_list(vector<int> *list) {
if (list->size() == N) {
for (int n: *list) {
cout << n;
}
cout << " " << endl;
}
}
void rec_alg(vector<int> *list, int step, int level){
print_list(list);
if (list->size() < N) {
if (step % 2 == 1) {
list->push_back(level);
rec_alg(list, 1, level+1);
if (list->size() >= 2) {
for (int i = list->size() - 1; i > 0; i--) {
iter_swap(list->begin() + i, list->begin() + i - 1);
// print_list(list);
rec_alg(list, i+1, level+1);
}
}
list->erase(list->begin() + 0);
} else {
list->insert(list->begin() + 0, level);
rec_alg(list, 0, level+1);
if (list->size() > 2) {
for(int i = 0; i < list->size() - 1; i++) {
iter_swap(list->begin() + i, list->begin() + i + 1);
rec_alg(list, i+1, level+1);
}
}
list->erase(list->begin() + list->size() - 1);
print_list(list);
}
}
}
int main()
{
vector<int> list = {1};
int step = 1; // номер перестановки
int level = 1; // номер этажа дерева
rec_alg(&list, step, level+1);
}