方便大家使用的c版本 算法
源代码在线查看: heapsort.cpp
//利用最小堆相关操作进行堆排序heapsort.cpp
#include
#include
#include
#include
typedef int ElemType;
#include "minheap.cpp"
#include "linelist.cpp"
void PrintList(List *L)
{int i,n;
ElemType e;
n=L->ListLength();
for(i=0;i {cout if((i+1)%10==0) cout cout }
void HeapSort(List *L)
{int i,n;
ElemType e;
n=L->ListLength();
minheap H(n);
for(i=0;i H.heapInsert(L->GetElem(i,&e));
L->ClearList();i=0;
while(!H.heapEmpty())
L->ListInsert(i++,H.heapDelete());
H.Destroyheap();
}
void main()
{cout int i;
List L;
L.init(&L);
srand(300);
for(i=0;i L.ListInsert(i,rand()%100);
cout PrintList(&L);
HeapSort(&L);
cout PrintList(&L);
L.DestroyList(L);
cin.get();}