Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public E last()
  2. {
  3. if (root == null)
  4. {
  5. throw new NullPointerException("Set's root is null in "
  6. + "E last()");
  7.  
  8. }
  9. BstNode<E> node = root;
  10. while (node.right != null)
  11. {
  12. node = node.right;
  13.  
  14. }
  15. return node.element;
  16.  
  17. }
  18. public Set<E> tailSet(E element) {
  19. Set<E> list = new BstSet();
  20. if (root != null && element != null) {
  21. setTailRecursive(element, root, list);
  22. }
  23. return list;
  24. }
  25. private void setTailRecursive(E element, BstNode<E> node, Set<E> list) {
  26. if (node != null) {
  27. if (element.compareTo(node.element) < 0) {
  28. list.add(node.element);
  29. }
  30. setTailRecursive(element, node.right, list);
  31. setTailRecursive(element, node.left, list);
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement