Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. private void updateHeap(int i) {
  2.         int left = 2 * i+1;
  3.         int right = 2 * i + 2;
  4.         int max = i;
  5.         if (left < size && vector[left] > vector[i]) {
  6.             max = left;
  7.         }
  8.         if (right < size && vector[right] > vector[max]) {
  9.             max = right;
  10.         }
  11.         if (max != i) {
  12.             swap(vector, i, max);
  13.             updateHeap(max);
  14.         }
  15.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement