Modify the author's BinarySearchTree code to implement some new methods as shown below.
a) rotateRight
Performs a single rotation on the node having the passed value.
Example:
If a RotateRight on 100 is performed:
100 50
/ /
50 150 --> 40 100
/
40 45 150
45
b) rotateLeft
Similar to above but instead a left rotation.
c) copy
Creates and returns a new tree that is a copy of the original tree.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
23 | 24 | 25 | 26 | 27 | 28 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 1 | 2 | 3 | 4 | 5 |
Get Free Quote!
328 Experts Online