Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1.     public void Add(int i) {
  2.        
  3.         boolean fertig = false;
  4.        
  5.         Node h;
  6.        
  7.         if(root == null) {
  8.             root = new Node(i);
  9.             return;
  10.         }
  11.         else {
  12.            
  13.             h = root;
  14.            
  15.             while(!fertig) {
  16.                 if(i>h.value && h.right != null) {
  17.                     h=h.right;
  18.                 }
  19.                 if(i<h.value && h.left != null) {
  20.                     h=h.left;
  21.                 }
  22.                 if(i>h.value && h.right == null) {
  23.                     h.right = new Node(i);
  24.                     fertig = true;
  25.                 }
  26.                 if(i<h.value && h.left == null) {
  27.                     h.left = new Node(i);
  28.                     fertig = true;
  29.                 }
  30.             }  
  31.         }  
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement