Advertisement
Guest User

Untitled

a guest
Sep 12th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. void heapify(int* arr, int arrLength){
  2.     int root;
  3.     int i;
  4.    
  5.     for(i=1;i<(arrLength-1);i++){
  6.         root=(i-1)/2;
  7.         if(arr[i]>arr[root]){
  8.             swap(arr,i,root);
  9.             if(i!=0){
  10.                 i=root-1;
  11.             }
  12.             else{
  13.                 i=0;
  14.             }
  15.         }
  16.     }
  17. }
  18. void heapSort(int* arr, int arrLength){
  19.     int i;
  20.     heapify(arr,arrLength);
  21.     for(i=(arrLength-1);i>0;i--){
  22.         swap(arr,0,i);
  23.         heapify(arr,i);
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement