swap child and parent until parent is smaller
while ( arr [ j ] > arr [ ( j - 1 ) / 2 ] ) { swap ( arr [ j ] , arr [ ( j - 1 ) / 2 ] ) ; j = ( j - 1 ) / 2 ; } } } } void heapSort ( int arr [ ] , int n ) { buildMaxHeap ( arr , n ) ; for ( int i = n - 1 ; i > 0 ; i -- ) {