?? heapsort.txt
字號(hào):
//利用最小堆相關(guān)操作進(jìn)行堆排序heapsort.cpp
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
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<n;i++)
{cout<<setw(4)<<L->GetElem(i,&e);
if((i+1)%10==0) cout<<endl;}
cout<<endl;
}
void HeapSort(List *L)
{int i,n;
ElemType e;
n=L->ListLength();
minheap H(n);
for(i=0;i<n;i++)
H.heapInsert(L->GetElem(i,&e));
L->ClearList();i=0;
while(!H.heapEmpty())
L->ListInsert(i++,H.heapDelete());
H.Destroyheap();
}
void main()
{cout<<"heapsort.cpp運(yùn)行結(jié)果:\n";
int i;
List L;
L.init(&L);
for(i=0;i<10;i++)
L.ListInsert(i,random(50));
cout<<"原表:\n";
PrintList(&L);
HeapSort(&L);
cout<<"排序后表:\n";
PrintList(&L);
L.DestroyList(L);
getch();}
heapsort.cpp運(yùn)行結(jié)果:
原表:
49 4 36 44 12 33 6 34 36 11
排序后表:
4 6 11 12 33 34 36 36 44 49
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -