简单选择排序
简单的排序处理流程
(1)从待排序序列中,找到关键字最小的元素;
(2)如果最小元素不是待排序序列的第一个元素,将其和第一个元素互换;
(3)从余下的N-1个元素中,找出关键字最小的元素,重复(1)、(2)步,直到排序结束。
|
|
堆排序
二叉堆是完全二叉树或者是近似完全二叉树。
二叉堆满足两个特性:
1、父节点的键值总是大于或等于(小于或等于)任何一个子节点的键值。
2、每个结点的左子树和右子树123456789101112def heap_adjust(data, s, m): if 2*s > m: return temp = s - 1 if data[2*s-1] > data[temp]: temp = 2*s - 1 if 2*s <= m-1 and data[2*s] > data[temp]: temp = 2*s if temp<> s-1: