剑指OFFER之最小堆篇
来源:互联网 发布:蓝光播放器 mac 破解 编辑:程序博客网 时间:2024/05/21 08:01
#include <stdio.h>void heap_adjust(int a[], int start, int end){ int temp; int i; temp = a[start]; for (i = 2 * start + 1; i <= end; i = i * 2 + 1) { if (i < end && a[i] > a[i+1]) { i++; } if (temp <= a[i]) { break; } else { a[start] = a[i]; start = i; } } a[start] = temp;}void heap_create(int a[], int n){ int i; for (i = n/2 - 1; i >= 0; i--) { heap_adjust(a, i, n - 1); }}void heap_sort(int a[], int n){ int i; for (i = 1; i < n; i++) { printf("%d ", a[0]); a[0] = a[n - i]; heap_adjust(a, 0, n - 1 - i); }}/* 面试题30:最大的k个数 */void get_biggest_k_numbers(int input[], int n, int k){ int i; if (!input || n <= 0 || n < k || k <= 0) { return; } heap_create(input, k); for (i = k; i < n; i++) { if (input[i] > input[0]) { input[0] = input[i]; heap_adjust(input, 0, k - 1); } }}
0 0
- 剑指OFFER之最小堆篇
- 【剑指offer】 堆排序查找最小的K个数
- 剑指Offer-30-最小的k个数-最大堆
- 剑指Offer之 - 最小的k个数
- 剑指offer之最小的k个数
- 【剑指offer】之最小的k个数
- 剑指offer之最小的K个数
- 堆排序之最小堆
- 数据结构之最小堆
- 堆排序-剑指offer
- 剑指offer-堆排序
- 剑指Offer面试题30最小的K个数(涉及堆或快排)
- 基本数据结构之最大堆最小堆
- 剑指Offer之旋转数组的最小数字
- 剑指Offer之把数组排成最小的数
- 《剑指Offer》之面试题旋转数组的最小数字
- 剑指Offer之 - 旋转数组的最小数字
- 剑指offer之把数组排成最小的数
- 剑指OFFER之队列
- 用Python和Pygame写游戏-从入门到精通(3)
- 【单步调试】 VC
- 梦想从这里开始,退一步海阔天空
- 文本框的长度限制,和类别
- 剑指OFFER之最小堆篇
- IIS服务器应用程序不可用的解决办法
- C#为控件添加拖拽文件事件
- Annotation注解处理器
- 生产者和消费者 用Semaphore来控制线程
- Makefile(转自CSDN)
- Ubuntu下设置SSH服务
- git首次提交代码到github报错
- 走在精英团队的路上