Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void heapify(int* arr, int arrLength){
- int root;
- int i;
- for(i=1;i<(arrLength-1);i++){
- root=(i-1)/2;
- if(arr[i]>arr[root]){
- swap(arr,i,root);
- if(i!=0){
- i=root-1;
- }
- else{
- i=0;
- }
- }
- }
- }
- void heapSort(int* arr, int arrLength){
- int i;
- heapify(arr,arrLength);
- for(i=(arrLength-1);i>0;i--){
- swap(arr,0,i);
- heapify(arr,i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement