文件名称:dan
介绍说明--下载内容均来自于网络,请自行研究使用
// 堆排序
// 初始调用BuildMaxHeap将a[1..size]变成最大堆
// 因为数组最大元素在a[1],则可以通过将a[1]与a[size]互换达到正确位置
// 现在新的根元素破坏了最大堆的性质,所以调用MaxHeapify调整,
// 使a[1..size-1]成为最大堆,a[1]又是a[1..size-1]中的最大元素,
// 将a[1]与a[size-1]互换达到正确位置。
// 反复调用Heapify,使整个数组成从小到大排序。
// 注意: 交换只是破坏了以a[1]为根的二叉树最大堆性质,它的左右子二叉树还是具备最大堆性质。
// 这也是为何在BuildMaxHeap时需要遍历size/2到1的结点才能构成最大堆,而这里只需要堆化a[1]即可。-//Heap sort// initial call BuildMaxHeap will become the largest heap a [1 .. size]// the array largest element in a [1], then by a [1] and a [size] interchangeable reach correct position// new root element destroyed maximum heap nature so call MaxHeapify adjusted,// a [1 .. size-1] the maximum heap, a [1] a [1 .. size- The largest element 1],// a [1] with a [size-1] interchangeable achieve the correct position.// Repeatedly call Heapify, so that the entire number of small to large.// Note: The to exchange just destroyed a [1] is the root of the binary tree maximum heap nature, its left and right sub-binary tree or with maximum heap nature.// This is why BuildMaxHeap when you need to traverse the size/2 to 1 node in order to constitute maximum heap, only need to heap of a [1] can be.
// 初始调用BuildMaxHeap将a[1..size]变成最大堆
// 因为数组最大元素在a[1],则可以通过将a[1]与a[size]互换达到正确位置
// 现在新的根元素破坏了最大堆的性质,所以调用MaxHeapify调整,
// 使a[1..size-1]成为最大堆,a[1]又是a[1..size-1]中的最大元素,
// 将a[1]与a[size-1]互换达到正确位置。
// 反复调用Heapify,使整个数组成从小到大排序。
// 注意: 交换只是破坏了以a[1]为根的二叉树最大堆性质,它的左右子二叉树还是具备最大堆性质。
// 这也是为何在BuildMaxHeap时需要遍历size/2到1的结点才能构成最大堆,而这里只需要堆化a[1]即可。-//Heap sort// initial call BuildMaxHeap will become the largest heap a [1 .. size]// the array largest element in a [1], then by a [1] and a [size] interchangeable reach correct position// new root element destroyed maximum heap nature so call MaxHeapify adjusted,// a [1 .. size-1] the maximum heap, a [1] a [1 .. size- The largest element 1],// a [1] with a [size-1] interchangeable achieve the correct position.// Repeatedly call Heapify, so that the entire number of small to large.// Note: The to exchange just destroyed a [1] is the root of the binary tree maximum heap nature, its left and right sub-binary tree or with maximum heap nature.// This is why BuildMaxHeap when you need to traverse the size/2 to 1 node in order to constitute maximum heap, only need to heap of a [1] can be.
(系统自动生成,下载前可以参看下载内容)
下载文件列表
dan.cpp