void HeapSort(int *A, int len) { BuildMaxHeap(A,len); for(int i = len-1; i > 1; i--){ swap(A[1],A[]) } }
void HeapSort(int list[], int num) { int k; int heapsize = num; /* Create Max-Heap */ BuildMaxHeap(list, heapsize); printf("After build heap, lets check...\n"); for(k=1; k <= num; k++) printf("[%d]", arr[k]); printf("\n"); /* Until heapsize is 1, Swap root node of Max heap with last child and call Max-Heap*/ while(heapsize >1) { /*Swap */ int temp = list[1]; list[1] = list[heapsize]; list[heapsize] = temp; heapsize--; MaxHeapify(list, 1, heapsize); } }
void HeapSort(int* pBuffer, unsigned int nLen) { BuildMaxHeap(pBuffer, nLen); for (int i = nLen - 1; i > 0; --i) { std::swap(pBuffer[i], pBuffer[0]); MaxHeapify(pBuffer, 0, i); } }
void HeapSort(ElementType S[], long N) { long i; BuildMaxHeap(S, N); for (i = N - 1; i > 0; i--) { Swap(&S[0], &S[i]); TuneMaxHeap(S, 0, i); } }
void HeapSort(int *pnArr, int nLen) { BuildMaxHeap(pnArr, nLen); for (int i = nLen - 1; i > 0; i--) { Swap(&pnArr[i], &pnArr[0]); nLen--; MaxHeapify(pnArr, nLen, 0); } }
void HeapSort(int *array, int length) { BuildMaxHeap(array, length); int temp; int heap_size = length; while(heap_size > 1) { temp = array[0]; array[0] = array[heap_size-1]; array[heap_size-1] = temp; MaxHeapify(array, 0, --heap_size); } }
void HeapSort(int *A, int length) { BuildMaxHeap(A, length); int heapsize = length; for (int i = length; i > 0; i--) { int temp = A[0]; A[0] = A[i-1]; A[i-1] = temp; heapsize--; MaxHeapify(A, 1, heapsize); } }
void PartialHeapSort(int* pBuffer, uint32_t nLen, uint32_t nPartialSize) { BuildMaxHeap(pBuffer, nLen); for (int i = nLen - 1; i > nLen - nPartialSize - 1; --i) { std::swap(pBuffer[i], pBuffer[0]); MaxHeapify(pBuffer, 0, i); } for (int i = 0; i < nPartialSize + 1; ++i) { std::swap(pBuffer[i], pBuffer[nLen - 1 - i]); } }
void Heap_Sort(int *a, int n) { BuildMaxHeap(a,n); int i; int temp = a[0]; a[0] = a[n-1]; a[n-1] = temp; for (i=n-2;i>0;i--) { Max_Heapify(a,0,i); temp = a[0]; a[0] = a[i]; a[i] = temp; } }
void HeapSort(int* arr, int size) { Heap* heap = MakeHeap(arr, size); BuildMaxHeap(heap); for (int i = size; i > 0; --i) { arr[i - 1] = heap->element[1]; heap->element[1] = heap->element[heap->size]; heap->size = heap->size - 1; MaxHeapify(heap, 1); } }
//Heap sort: void HeapSort(int a[], int length) { int i; int temp; BuildMaxHeap(a, length); for(i = length - 1; i > 0; i--) { temp = a[i]; a[i] = a[0]; a[0] = temp; MaxHeapIFY(a, 0, i); } }