文件名称:dan
-
所属分类:
- 标签属性:
- 上传时间:2012-12-22
-
文件大小:1.06kb
-
已下载:0次
-
提 供 者:
-
相关连接:无下载说明:别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容来自于网络,使用问题请自行百度
// 堆排序
// 初始调用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
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.