#include < iostream . h > #include < conio . h > int heapsize , length ; void exchange ( int & a , int & b ) { int temp ; temp = a ; a = b ; b = temp ; } void maxheapify ( int a [ ] , int i ) { int l , r , largest , temp ; l = 2 * i ; //left[i] r = 2 * i + 1 ; //right[i] if ( l <= heapsize && a [ l ] > a [ i ] ) largest = l ; else largest = i ; if ( r <= heapsize && a [ r ] > a [ largest ] ) largest = r ; if ( largest != i ) { exchange ( a [ i ] , a [ largest ] ) ; maxheapify ( a , largest ) ; } } void buildmaxheap ( int a [ ] ) { heapsize = length ; for ( int i = length / 2 ; i >= 1 ; i -- ) maxheapify ( a , i ) ; } void heapsort ( int a [ ] ) { buildmaxheap ( a ) ; for ( int i = length ; i >= 2 ; i -- ) { exchange ( a [ 1 ] , a [ i ] ) ; heapsize -= 1 ; maxheapify ( a , 1 ) ; } } void main ( ) { clrscr