#include <stdio.h>
#include <stdlib.h>
// 交换函数,交换数组中的两个数
void swap(int array[], int i, int j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
// 维护tree中下标为i的结点,使其满足堆的性质
// n: tree中结点的数量
// i: 当前要维护的结点的下标
void heapify(int tree[], int n, int i) {
// 如果当前结点下标越界,直接返回(其实通过下面的条件控制,已经可以避免出现这种情况)
if (i >&#
堆排序-(数组实现 C语言版本)
最新推荐文章于 2022-08-21 20:32:24 发布
#include <stdio.h>#include <stdlib.h>// 交换函数,交换数组中的两个数void swap(int array[], int i, int j) { int temp = array[i]; array[i] = array[j]; array[j] = temp;}// 维护tree中下标为i的结点,使其满足堆的性质// n: tree中结点的数量// i: 当前要维护的结点的下标void heapif
摘要由CSDN通过智能技术生成