Aldin-SXR

sink()

May 6th, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. /* Node demotion:
  2.  * sink down a node to its correct position */
  3. private void sink(int k) {
  4.     while (2*k <= length) {                     // 1
  5.         int j = 2 * k;                          // 2
  6.         if (j < length && less(j, j + 1)) {     // 2
  7.             j++;                                // 2
  8.         }
  9.            
  10.         if (!less(k, j)) {                      // 3
  11.             break;                              // 3
  12.         }
  13.            
  14.         swap(k, j);                             // 4
  15.         k = j;                                  // 5
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment