资源简介
建堆 堆排序 小顶堆
算法学习用,有什么好的建议欢迎告诉我呀,先谢谢大家的帮助
代码片段和文件信息
// 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
评论
共有 条评论