SHARE
TWEET

Untitled

a guest Oct 21st, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void siftdown(int *array, int top, int bot) {
  2.     int max, value =0;
  3.     while ((top * 2 <= bot) && value < 1){
  4.         if(top * 2 == bot){
  5.             max = top * 2;
  6.  
  7.         } else if (array[top * 2] > array[top * 2 + 1]){
  8.             max = top * 2;
  9.         } else {
  10.             max = top * 2 + 1;
  11.         }
  12.         if (array[top] < array[max]){
  13.             int x = array[top];
  14.             array[top] = array[max];
  15.             array[max] = x;
  16.             top = max;
  17.         } else {
  18.             value = 1;
  19.         }
  20.     }
  21. }
  22.  
  23. void sort(int *array, int size){
  24.     for (int i = (size / 2) - 1; i >= 0; i--){
  25.         siftdown(array, i, size - 1);
  26.     }
  27.     for (int i = size - 1; i >= 1; i--)
  28.     {
  29.         int x = array[0];
  30.         array[0] = array[i];
  31.         array[i] = x;
  32.         siftdown(array, 0, i - 1);
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top