程序代写代做代考 #### Question 9

#### Question 9

You will be implementing the following methods in the `BinaryTree` class:

– `bool isSame(const BinaryTree & other) const;`

Given two binary trees, determine the if they are identical.

`tree1.isSame(tree2)` should return `true` if `tree1` and `tree2` have the same
structure and values. If they do not, `isSame` should return `false`.

For example, the following two binary trees are not identical:

“`
17 17
/ \ / \
15 24 15 24
/ \ / \ / \
12 16 22 26 12 16
“`

Neither are these two binary trees:

“`
17 15
/ \ / \
15 24 12 17
/ \ / \
12 16 16 24
“`

The following two two binary tres are identical:

“`
17 17
/ \ / \
24 15 24 15
“`

**Write your solution in `binarytree_q9.cpp`.**

– – –

#### Question 10

You will be implementing the following methods in the `BinaryTree` class:

– `void makeNeighbors();`

Write a function `makeNeighbors()` that connects the nodes of a binary tree to
the immediate right node of the tree.

The connections are made level wise and the rightmost node in the level
connects to `NULL`.

Make a member variable in the node struct called `neighbor` (along with left
and right) of type `Node *` in the following manner:

`Node * neighbor`;

Example, the following tree:

“`
9
/ \
3 2
/ \ \
4 1 6
“`

must become:

“`
9 —> NULL
/ \
3 —>2 —> NULL
/ \ \
4 ->1 —> 6 —> NULL
“`

where the horizontal links represent the neighbor links.

*Hint: You can use a `std::queue` to do this.*

Here are the function signatures you might need: (`T` is the queue’s template
parameter.)

– `bool empty() const;`
– `T& front();`
– `void push (const T& val);`
– `void pop();`
– `T& back();`

**Write your solution in `binarytree_q10.cpp`.**