/* Print the tree in inorder */ void print_tree_inorder(struct node *root) { if(root == NULL) return; print_tree_inorder(root->left_child); printf("%d ", root->data); print_tree_inorder(root->right_child); }
void print_tree_inorder (const std::shared_ptr<BTN<T>>& root) { if (!root) { return; } print_tree_inorder(root->left); std::cout << *root << std::endl; print_tree_inorder(root->right); }
int main() { /* 1. Inserting the elements. 2. Searching the elements. 3. Inroder, postorder and preorder. 4. Height of the tree. */ struct node *root = NULL; insert_elements(&root, 5); insert_elements(&root, 5); insert_elements(&root, 3); insert_elements(&root, 7); printf("\nHeight of the BST: %d\n", height_BST(root)); insert_elements(&root, 1); insert_elements(&root, 2); insert_elements(&root, 6); insert_elements(&root, 8); print_tree_inorder(root); printf("\n"); //print_tree_postorder(root); insert_elements(&root, 22); print_tree_postorder(root); printf("\n"); print_tree_preorder(root); printf("\n"); // A tree with only the root is of height 0 printf("\nHeight of the BST: %d\n", height_BST(root)); printf("\n%d\n", search_elements(&root, 4)); }