Chang, Chi-Hung
The most common tree that for any parents, there will be at most 2 children
struct node{ int value; struct node* left; struct node* right; } struct node* root = malloc(sizeof(struct node));
Suppose AAA is a node that we are going to insert a new node BBB to its left child.
struct node* B = malloc(sizeof(struct node)); B->left = NULL; B->right = NULL; A->left = B;
Suppose we want to remove AAA's left node.
free(A->left); A->left = NULL;
Order: left →\to→ root →\to→ right 1→3→4→6→7→8→10→13→141 \to 3 \to 4 \to 6 \to 7 \to 8 \to 10 \to 13 \to 141→3→4→6→7→8→10→13→14
Order: root →\to→ left →\to→ right 8→3→1→6→4→7→10→14→138 \to 3 \to 1 \to 6 \to 4 \to 7 \to 10 \to 14 \to 138→3→1→6→4→7→10→14→13
Order: left →\to→ right →\to→ root 1→4→7→6→3→13→14→10→81 \to 4 \to 7 \to 6 \to 3 \to 13 \to 14 \to 10 \to 81→4→7→6→3→13→14→10→8
Give you the elements of a binary tree. The first element is the root node. When getting a new node (number), you should add the node into the binary tree. Please create the binary tree and print out the tree in postorder.
8 3 10 1 6 14 4 7 13
1 4 7 6 3 13 14 10 8