BinaryTreeADT.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * BinaryTreeADT defines the interface to a binary tree data structure.
  3. *
  4. * @author Dr. Lewis
  5. * @author Dr. Chase
  6. * @version 1.0, 8/19/08
  7. */
  8. import java.util.Iterator;
  9. public interface BinaryTreeADT<T> {
  10. /**
  11. * Returns a reference to the root element
  12. *
  13. * @return a reference to the root
  14. */
  15. public T getRoot ();
  16. /**
  17. * Returns true if this binary tree is empty and false otherwise.
  18. *
  19. * @return true if this binary tree is empty
  20. */
  21. public boolean isEmpty();
  22. /**
  23. * Returns the number of elements in this binary tree.
  24. *
  25. * @return the integer number of elements in this tree
  26. */
  27. public int size();
  28. /**
  29. * Returns true if the binary tree contains an element that matches
  30. * the specified element and false otherwise.
  31. *
  32. * @param targetElement the element being sought in the tree
  33. * @return true if the tree contains the target element
  34. */
  35. public boolean contains (T targetElement);
  36. /**
  37. * Returns a reference to the specified element if it is found in
  38. * this binary tree. Throws an exception if the specified element
  39. * is not found.
  40. *
  41. * @param targetElement the element being sought in the tree
  42. * @return a reference to the specified element
  43. */
  44. public Node<T> find (T targetElement);
  45. /**
  46. * Returns the string representation of the binary tree.
  47. *
  48. * @return a string representation of the binary tree
  49. */
  50. public String toString();
  51. /**
  52. * Performs an inorder traversal on this binary tree by calling an
  53. * overloaded, recursive inorder method that starts with the root.
  54. *
  55. * @return an iterator over the elements of this binary tree
  56. */
  57. public Iterator<T> iteratorInOrder();
  58. /**
  59. * Performs a preorder traversal on this binary tree by calling an
  60. * overloaded, recursive preorder method that starts with the root.
  61. *
  62. * @return an iterator over the elements of this binary tree
  63. */
  64. public Iterator<T> iteratorPreOrder();
  65. /**
  66. * Performs a postorder traversal on this binary tree by calling an
  67. * overloaded, recursive postorder method that starts with the root.
  68. *
  69. * @return an iterator over the elements of this binary tree
  70. */
  71. public Iterator<T> iteratorPostOrder();
  72. /**
  73. * Performs a levelorder traversal on the binary tree, using a queue.
  74. *
  75. * @return an iterator over the elements of this binary tree
  76. */
  77. public Iterator<T> iteratorLevelOrder();
  78. }