I attempted all three. My approach was to try all three before looking at the on-line solutions. I decided to not use recursion, and use a brute force, straightforward approach to building the tree. I ended up using a value class as the inner class, after first trying to make the inner class be a ref class. I successfully built the tree using native and clr code, in problems 4 and 5. I decided to make my printout of the nodes be a dump of node pointers/numbers and their stored values, rather than try to print out in ascending values. This approach let me see that the tree was built properly.
I attempted to do the generic BinaryTree exercise, problem 6. Note this book is my first exposure to CLR. I feel that the book did not prepare me well enough for problem 6. One reason is the following. The on-line solution uses:
Code:
generic<typename T > where T:IComparable ref class BinaryTree
.
I have not found the âwhere T:IComparableâ syntax in chapter 9. If
Code:
generic<typename T > ref class BinaryTree :IComparable
is used instead, the code will not compile. (Please explain, if you know why this is so.)
I would like to add that overall, I am very satisfied with the book and exercises through chapter 9, which is as far as I have gotten so far.