堆的特性
1.每个节点最多可以有两个节点
2.根节点的键值是所有堆节点键值中最大者,且每个结点的值都比其孩子的值大
3.除了根节点没有兄弟节点,最后一个左子节点可以没有兄弟节点,其他节点必须有兄弟节点

堆是你见过的最有个性的树!它是用数组表示的树

堆的基本实现
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define DEFAULT_CAPCITY 128
typedef struct heap
{
int* arr; //储存元素的数组
int size; //当前已储存的元素个数
int capacity; //当前储存的容量
}Heap;
//初始化堆
bool initHeap(Heap& heap, int* orginal, int size);
//建堆
static void buildHeap(Heap& heap);
//将当前的节点和叶子节点调成最大堆
static void adjustDown(Heap& heap, int index);
bool initHeap(Heap& heap, int* orginal, int size)
{
int capacity = DEFAULT_CAPCITY > size ? DEFAULT_CAPCITY :