資源簡介
建堆 堆排序 小頂堆
算法學習用,有什么好的建議歡迎告訴我呀,先謝謝大家的幫助
代碼片段和文件信息
//?heapopr.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?
#include?
#include?
typedef?struct??
{
int?num[1024];
int?len;
}HeapDT;
void?HeapSort(HeapDT?&dt);
void?BuildHeap(HeapDT?&dt);
void?DownProcess(HeapDT?&dt?int?index);
void?PrintHeap(const?char*?strMsg?HeapDT?&dt);
void?Swap(HeapDT?&dt?int?v?int?u);
int?_tmain(int?argc?_TCHAR*?argv[])
{
int?data[13]?=?{85461371912113102};
HeapDT?dt;
memset(&dt?0?sizeof(HeapDT));
dt.len?=?13;
for?(int?i?=?0;?i?<=?12;?i++)
{
dt.num[i]?=?data[i];?
}
HeapSort(dt);
scanf(“%d“?&dt.len);
return?0;
}
void?HeapSort(HeapDT?&dt){
int?i;
int?iLength?=?dt.len;
PrintHeap(“Before?Sort:“?dt);
BuildHeap(dt);???//build?small-heap
for(?i=iLength-1;?i>=1;?i--)
{
Swap(dt?0?i);
dt.len
評論
共有 條評論