-
Notifications
You must be signed in to change notification settings - Fork 980
/
Copy pathmain.cc
36 lines (33 loc) · 877 Bytes
/
main.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
#include "solution.h"
#include <iostream>
#include <queue>
#include <algorithm>
void print_bfs(TreeNode* p)
{
if (!p) return;
std::vector<std::string> retv;
std::queue<TreeNode *> q;
q.push(p);
do {
TreeNode *node = q.front(); q.pop();
if (node)
retv.push_back(std::to_string(node->val));
else {
retv.push_back("#");
continue;
}
q.push(node->left);
q.push(node->right);
} while (!q.empty());
auto found = std::find_if(retv.rbegin(), retv.rend(), [](const std::string &s){ return s != "#"; });
retv.erase(found.base(), retv.end());
for (const auto &s : retv)
std::cout << s << ",";
std::cout << "\b " << std::endl;
}
int main()
{
Solution s;
std::vector<int> array{3,2,1,6,0,5};
print_bfs(s.constructMaximumBinaryTree(array));
}