-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
82 lines (74 loc) · 1.66 KB
/
test.cpp
File metadata and controls
82 lines (74 loc) · 1.66 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include"bintree.h"
// #define NO_COLOR
// #define NO_UNICODE
#include"treeHelper.hpp"
#include<cstdio>
#include<iostream>
using namespace std;
void cube(Node * n) {
if (n == nullptr) return;
n->data *= n->data;
cube(n->left);
cube(n->right);
}
void change_nulls_to(Node *& n, Node * x) {
if (n == nullptr) {
n = x;
return;
}
change_nulls_to(n->left, x);
change_nulls_to(n->right, x);
}
Node *& random_null(Node *& n) {
if (n == nullptr) return n;
if (rand() % 2) {
return random_null(n->left);
} else {
return random_null(n->right);
}
}
Node * random_node(Node * n) {
switch (rand() % 3) {
case 0:
{
if (n->left) {
return random_node(n->left);
} else {
return n;
}
break;
}
case 1:
{
if (n->right) {
return random_node(n->right);
} else {
return n;
}
break;
}
default:
{
return n;
break;
}
}
}
void add_loops(Node * root, int count) {
for (int i = 0; i < count; ++i) {
random_null(root) = random_node(root);
}
}
int main() {
auto root = rand_gen(30, 1);
cube(root);
cube(root);
add_loops(root, 2);
WrappedTree<Node> wt(root);
cout << wt;
// auto & n = find(root, 7);
// if (n != nullptr) remove_node(n);
// auto [oldt, newt] = wt.compare_to(WrappedTree(root));
// cout << oldt << newt;
// destroy(root);
}