Scortch/sort.c
///	Heap Sort organizes elements into a heap then extracts elements from the heap in sorted order
Heap Sort organizes elements into a heap then extracts elements from the heap in sorted order
Heap Sort organizes elements into a heap then extracts elements from the heap in sorted order
void heapSort(void *array, size_t count, size_t size, void *temporary, struct SortingStatistics *statistics, Compare compare, void *context) {
	if ( count < 2 ) {
		return;
	}
	size_t start = count / 2;
	while ( start > 0 ) {
		start -= 1;
		heapSift(array, start, count - 1, size, temporary, statistics, compare, context);
	}
	size_t end = count - 1;
	while ( end > 0 ) {
		swapAt(array, 0, end, size, temporary, statistics);
		end -= 1;
		heapSift(array, 0, end, size, temporary, statistics, compare, context);
	}
}
void heapSort ( void * array , size_t count , size_t size , void * temporary , struct SortingStatistics * statistics , Compare compare , void * context ) { if ( count < 2 ) { return ; } size_t start = count / 2 ; while ( start > 0 ) { start -= 1 ; heapSift ( array , start , count - 1 , size , temporary , statistics , compare , context ) ; } size_t end = count - 1 ; while ( end > 0 ) { swapAt ( array , 0 , end , size , temporary , statistics ) ; end -= 1 ; heapSift ( array , 0 , end , size , temporary , statistics , compare , context ) ; } }
Heap Sort organizes elements into a heap then extracts elements from the heap in sorted order
Heap Sort organizes elements into a heap then extracts elements from the heap in sorted order