Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. void Heap::repairDown(int index){
  2.     int leftChildIndex = 2 * index + 1;
  3.     int rightChildIndex = 2 * index + 2;
  4.  
  5.     if (leftChildIndex >= total) // koniec drzewa. Parametr index opisuje liΕ›Δ‡
  6.         return;
  7.  
  8.     int minIndex = index;
  9.  
  10.     if (data[index] < data[leftChildIndex])
  11.     {
  12.         minIndex = leftChildIndex;
  13.     }
  14.  
  15.     if ((rightChildIndex < total) && (data[minIndex] < data[rightChildIndex]))
  16.     {
  17.         minIndex = rightChildIndex;
  18.     }
  19.  
  20.     if (minIndex != index)
  21.     {
  22.         swap(minIndex, index);
  23.         repairDown(minIndex);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement