Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1.         private Integer next(int key) {
  2.             Node n = root;
  3.             int val = key;
  4.             while (n != null) {
  5.                 if (n.key <= key) {
  6.                     n = n.right;
  7.                 } else {
  8.                     val = n.key;
  9.                     n = n.left;
  10.                 }
  11.             }
  12.             return val == key ? null : val;
  13.         }
  14.  
  15.         private Integer prev(int key) {
  16.             Node n = root;
  17.             int val = key;
  18.             while (n != null) {
  19.                 if (n.key >= key) {
  20.                     n = n.left;
  21.                 } else {
  22.                     val = n.key;
  23.                     n = n.right;
  24.                 }
  25.             }
  26.             return val == key ? null : val;
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement