Binary Search Tree Problems

Tree Node Class

Write the following Member Functions for a Binary Search Tree Class for Tree holding Integer Objects
Given :
private TreeNode root; // in Tree Class

The following methods that are private methods are helper methods called by a public method from within a class that has the private data value root (so we can pass parameter). The public methods may directly access the root.
  1. public void insert(int n)
  2. private void printInOrder(TreeNode curr) // originally receives the root
  3. private void printReverseOrder(TreeNode curr)
  4. private void printPreOrder(TreeNode curr)
  5. private void printPostOrder(TreeNode curr)
  6. public void fill(int n) // fills tree with n random numbers
  7. private boolean isThere(TreeNode curr, int n) // return true if # in tree
  8. private int ctNodes(TreeNode curr)
  9. private int ctLeafs(TreeNode curr)
  10. private int ctNonLeafs(TreeNode curr)
  11. private TreeNode location(TreeNode curr, int n) // return null if not there
  12. private int height(TreeNode curr)
  13. private int smallest(TreeNode curr)
  14. public double average()
  15. private int ctNodeswith2kids(TreeNode curr)
  16. private int ctOddNums(TreeNode curr)
  17. private void changeEven(TreeNode curr) // change any even number to next odd number
  18. private void printOnlyEvenNumbers(TreeNode curr)
  19. private int sumOfLeafs(TreeNode curr)
  20. private void createTwins(TreeNode curr) // any node that has only 1 child - create twin for it
  21. private void printAncestors(TreeNode curr, String st)
    print ancestors of st. You may assume she is in the tree. Do it recursively and non-recursively. (Not hard - draw the picture)