-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-tree.cpp
37 lines (28 loc) · 1.16 KB
/
test-tree.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
// reference: https://www.programiz.com/dsa/breadth-first-search-tree <- link name has nothing to do
// https://en.wikipedia.org/wiki/Tree_traversal#cite_note-4
#include <iostream>
// see https://github.com/whoan/snip
// snip("cpp/binary-search-tree.hpp")
// snip("cpp/dfs.hpp")
// test it using any input from https://github.com/whoan/datasets/blob/master/binary-search-tree-lowest-common-ancestor
// example: curl -s https://raw.githubusercontent.com/whoan/datasets/master/binary-search-tree-lowest-common-ancestor/input-03.txt | ./a.out
int main() {
std::size_t numberOfElements;
std::cin >> numberOfElements;
auto binarySearchTree = snip::createBinarySearchTreeFromInput(numberOfElements);
auto root = binarySearchTree.getRoot();
std::cerr << "is a BST: " << snip::BST::isValid(root) << std::endl;
std::cerr << "pre order: ";
snip::DFS::preOrder(root);
std::cerr << std::endl;
std::cerr << "in order: ";
snip::DFS::inOrder(root);
std::cerr << std::endl;
std::cerr << "post order: ";
snip::DFS::postOrder(root);
std::cerr << std::endl;
std::cerr << "reverse in order: ";
snip::DFS::inOrderReverse(root);
std::cerr << std::endl;
return 0;
}