Due: Thursday 4/11 10:00am
Submission name: w18_treeStats
For this, you will need the TreeNode
and Tree
classes, which you can get here: https://github.com/nextcs-dw/dwsource/tree/main/TreeBasic
Make the following modifications to your Tree
class (reminder to keep your base cases to null
to make your code simpler):
- Add wrapper methods for
display()
,preOrder()
,inOrder()
, andpostOrder()
. countNodes(TreeNode current)
- Return the total number of nodes in the tree rooted at
current
. - Also include the wrapper function
countNodes()
- Return the total number of nodes in the tree rooted at
getHeight(TreeNode current)
- Return the height of the tree rooted at
current
. - Remember that the height may not be the same as the value of
numLevels
. - Also include the wrapper function
getHeight()
- Return the height of the tree rooted at
- Display the number of nodes and height in
setup()