-
Notifications
You must be signed in to change notification settings - Fork 981
/
Copy pathmain.cpp
57 lines (50 loc) · 1.1 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
#include <iostream>
#include "solution.h"
#include <vector>
using vecIter = std::vector<int>::iterator;
// Test Unit
//
// 1
// / \
// 2 3
// /\ /\
// 4 5 6 7
// /\ /\ /\ /\
// 8 9A BC DE F
// ( A == 10 ...)
TreeLinkNode *createBinaryTree(vecIter beg, vecIter end)
{
std::vector<TreeLinkNode *> vec;
for (vecIter it = beg; it != end; ++it)
vec.push_back(new TreeLinkNode(*it));
for (int i = 0, pos = 0; pos != vec.size()-1; ++i)
{
vec[i]->left = vec[++pos];
vec[i]->right = vec[++pos];
}
return *vec.begin();
}
void print(TreeLinkNode *root)
{
while (root)
{
std::cout << root->val;
TreeLinkNode *cur = root->next;
while (cur)
{
std::cout << "->" << cur->val;
cur = cur->next;
}
std::cout << std::endl;
root = root->left;
}
}
int main(int argc, char** argv)
{
std::vector<int> vec = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
TreeLinkNode *root = createBinaryTree(vec.begin(), vec.end());
Solution s;
s.connect(root);
print(root);
return 0;
}