-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09-binary-trees.cc
69 lines (63 loc) · 1.71 KB
/
09-binary-trees.cc
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
#include <iostream>
#include <limits>
using std::cin;
using std::cout;
using std::endl;
using std::numeric_limits;
#include "idebug.h"
#include "trees.h"
int main() {
int part;
cin >> part;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
while(part != -1) {
cout << "Part: " << part << "----------------------------------------";
cout << "--------------------------------" << endl;
switch(part) {
/* ---- 01 ------------------------------------------------------------ */
case 1: {
vector<int> v;
readArray(v);
BinaryTree<int> bt(v);
bool balanced = bt.isBalancedTree();
cout << "Balanced = " << balanced;
break;
}
/* ---- 05 ------------------------------------------------------------ */
case 5: {
vector<int> v;
readArray(v);
BinaryTree<int> bt(v);
bt.iterativeInOrderTraversal();
break;
}
/* ---- 06 ------------------------------------------------------------ */
case 6: {
vector<int> v;
readArray(v);
BinaryTree<int> bt(v);
int k;
cin >> k;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
bt.iterativeInOrderTraversal();
shared_ptr<BinaryTreeNode<int>> node = bt.findKthNode(k);
cout << k << "-th node is " << node->data << endl;
break;
}
/* ---- 07 ------------------------------------------------------------ */
case 7: {
vector<char> v;
readArray(v);
BinaryTree<char> bt;
printContainer(v);
bt.reconstructFromPreorder(v);
bt.print();
break;
}
default: {
break;
}
}
cin >> part;
}
}