| Problem 1 | Problem 3 |
| Problem 2 | Problem 4 |
50
20 60
10 40 70
15 30 62 80
23 34 75
In-order: 10 15 20 23 30 34 40 50 60 62 70 75 80 Pre-order: 50 20 10 15 40 30 23 34 60 70 62 80 75 Post-order: 15 10 23 34 30 40 20 62 75 80 70 60 50
One possibility is
50
23 60
10 40 70
15 34 62 80
75
Other possibilities have the left subtree of 50 being
15
10 40
34
23
or
15
10 40
23
34
struct Node
{
int data;
Node* left;
Node* right;
Node* parent;
};
void insertAuxiliary(Node*& n, int value, Node* par)
{
if (n == nullptr)
set n to point to a new Node whose data field is set to value,
whose left and right children are null, and whose parent field
is set to par.
else if (value < n->data)
insertAuxiliary(n->left, value, n);
else
insertAuxiliary(n->right, value, n);
}
void insert(Node*& n, int value)
{
insertAuxiliary(n, value, nullptr); // pass nullptr as parent of root
}
7
5 6
3 0 2
7 5 6 3 0 2
6 5 2 3 0