Пример #1
0
void Test1(BinarySearchTree<int> &tree) {
    tree.Print();
    if (!IsBalanced(tree.GetRoot()))
        printf("Not balanced\n");
    else
        printf("Balanced\n");
}
Пример #2
0
void Test(BinarySearchTree<int> &tree) {
    tree.Print();
    if (GetBalancedTreeHeight(tree.GetRoot()) == -1)
        printf("Not balanced\n");
    else
        printf("Balanced\n");
}
int main() {
    int p[] = {3, 9, 5, 7, 20, 1};
    int i[] = {9, 3, 1, 5, 20, 7};
    std::vector<int> postorder(p, p + 6);
    std::vector<int> inorder(i, i + 6);
    Node<int> *root = BuildTree(postorder, inorder);
    BinarySearchTree<int> tree;
    tree._root = root;
    tree.Print();
}
Пример #4
0
int main() {
    assert(NumTrees(4) == 14);
    std::vector<Node<int>*> result = GenerateTrees(4);
    for (int i = 0; i < result.size(); i++) {
        BinarySearchTree<int> tree;
        tree._root = result[i];
        tree.Print();
        std::cout << std::endl;
    }
    return 0;
}