`#include<iostream>#include<algorithm>using namespace std;//1.在N个数据当中找出最大的K个数const int N = 10000;const int K = 100;void AdjustDown1(int a[], int size, int parent)  //建一个小堆{	int child = parent * 2 + 1;	while (child < K)	{		if ((child + 1 < K) && (a[child + 1] < a[child]))		{			child++;		}		if (a[child] < a[parent])		{			swap(a[child], a[parent]);			parent = child;			child = parent * 2 + 1;		}		else		{			break;		}	}}void GetTopK(int a[],int TopK[]){	assert(K < N);	int i = 0;	int j = 0;	int m = 0;	int n = 0;	for (i = 0; i < K; i++)	{		TopK[i] = a[i];     //取出a中的前k个数字放到topk[]里面	}	//建堆	for (j = (K - 2) / 2; j >0; --j)	{		AdjustDown1(TopK,K,j);	}	for (int m = 0; m < N; ++m)	{		if (a[m]>TopK[0])		{			TopK[0] = a[m];			AdjustDown1(TopK, K, 0);		}	}	for (int n = 0; n < K; ++n)  //一次输出K个最大数	{		cout << TopK[n] << " ";	}	cout << endl;}`

`#include"BIgData.h"void TestTopK(){	int a[N];	int TopK[K];	for (int i = 0; i < N; ++i)	{		a[i] = i;	}	GetTopK(a, TopK);}int main(){	TestTopK();	system("pause");	return 0;}`

`//2.堆排序：建大堆，每次找到最大的数据交换到数组末尾，将剩下的数据AdjustDown，再进行交换void AdjustDown2(int a[],int size,size_t parent){	int child = parent * 2 + 1;	while (child<size)	{		if ((child + 1 < size)&&a[child] < a[child + 1])		{			++child;		}		if (a[child] > a[parent])   		{			swap(a[child], a[parent]);			parent = child;			child = parent * 2 + 1;		}		else		{			break;		}	}}void Heap_Sort(int a[], size_t n){	for (int i = (n - 2) / 2; i >= 0; i--)  //注意边界条件	{		AdjustDown2(a, n, i);	}	for (int i = 0; i < n; ++i)	{		swap(a[0], a[n - 1-i]);		AdjustDown2(a, n - 1 - i, 0);	}	for (int i = 0; i < n; ++i)	{		cout << a[i] << " ";	}	cout << endl;}`

`void TestHeap_Sort(){	int a[] = { 10, 12, 9, 15, 13, 17, 16, 18, 20,14 };	Heap_Sort(a, 10);}int main(){	TestHeap_Sort();	system("pause");	return 0;}`