You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.9 KiB

6 years ago
  1. // Binary Search Tree class
  2. // Xiwei Wang
  3. import java.util.*;
  4. public class BST
  5. {
  6. // instance variables
  7. private BSTNode m_root;
  8. private int m_size;
  9. // constructor
  10. public BST()
  11. {
  12. m_root = null;
  13. m_size = 0;
  14. }
  15. // This method returns the number of elements in the tree.
  16. // Do not make any changes to this method!
  17. public int size()
  18. {
  19. return m_size;
  20. }
  21. // This method clears the content of the tree.
  22. // Do not make any changes to this method!
  23. public void clear()
  24. {
  25. m_root = null;
  26. m_size = 0;
  27. }
  28. // This non-recursive method takes a string and inserts it into the binary
  29. // search tree, keeping the tree ordered.
  30. public void add(String value)
  31. {
  32. // TODO: implement this method using a non-recursive solution
  33. }
  34. // This non-recursive method returns a string that represents the in-order traversal
  35. // of the binary search tree.
  36. public String inOrder()
  37. {
  38. // TODO: implement this method using a non-recursive solution
  39. return ""; // replace this statement with your own return
  40. }
  41. // This method returns the smallest element in the binary search tree. You
  42. // are not allowed to create any additional structures, including but not
  43. // limited to arrays, stacks, queues, or other trees.
  44. public String min()
  45. {
  46. // TODO: implement this method using a non-recursive solution
  47. return ""; // replace this statement with your own return
  48. }
  49. // This method takes a reference to the root of the expression, evaluates
  50. // the tree, and returns the result as an int.
  51. public int evaluate(BSTNode node)
  52. {
  53. // TODO: implement this method using a non-recursive solution
  54. return -1; // replace this statement with your own return
  55. }
  56. }