/* Print the tree in postorder, there will be no change in the root so no need of sending the address of the root */ void print_tree_postorder(struct node *root) { if(root == NULL) return; print_tree_postorder(root->left_child); print_tree_postorder(root->right_child); printf("%d ", root->data); }
void print_tree_postorder (const std::shared_ptr<BTN<T>>& root) { if (!root) { return; } print_tree_postorder(root->left); print_tree_postorder(root->right); std::cout << *root << std::endl; }
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)); }