Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. public void removeItem() throws NoCurrentItem280Exception
  2.     {
  3.         // Go to the root, delete the root - root is replaced by the last item
  4.         root();
  5.         super.removeItem();
  6.        
  7.         // Perform necessary switches down through the tree
  8.         int node = 1;
  9.         while(findLeftChild(node) <= count) // A (left) child exists
  10.         {
  11.             // Get the left child
  12.             int child = findLeftChild(node);
  13.            
  14.             // If the right child exists, and it is the larger, get it instead
  15.             if (findRightChild(node) <= count && items[child].compareTo(items[findRightChild(node)]) >= 0)
  16.             {
  17.                 child = findRightChild(node);
  18.             }
  19.            
  20.             // If the parent is smaller than the root, switch them
  21.             if(items[node].compareTo(items[child]) >= 0)
  22.             {
  23.                 I current = items[node];
  24.                 items[node] = items[child];
  25.                 items[child] = current;
  26.                 node = child;
  27.             }
  28.            
  29.             else
  30.             {
  31.                 return;
  32.             }
  33.         }
  34.  
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement