Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void removeItem() throws NoCurrentItem280Exception
- {
- // Go to the root, delete the root - root is replaced by the last item
- root();
- super.removeItem();
- // Perform necessary switches down through the tree
- int node = 1;
- while(findLeftChild(node) <= count) // A (left) child exists
- {
- // Get the left child
- int child = findLeftChild(node);
- // If the right child exists, and it is the larger, get it instead
- if (findRightChild(node) <= count && items[child].compareTo(items[findRightChild(node)]) >= 0)
- {
- child = findRightChild(node);
- }
- // If the parent is smaller than the root, switch them
- if(items[node].compareTo(items[child]) >= 0)
- {
- I current = items[node];
- items[node] = items[child];
- items[child] = current;
- node = child;
- }
- else
- {
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement