插入所有节点后,从下往上不断输出当前结点的父节点即可。
#include <iostream>
using namespace std;
#define MinData -10010
typedef struct HeapStruct *MinHeap;
struct HeapStruct
{
int *arr;
int size, capacity;
};
MinHeap create(int maxsize)
{
MinHeap H = (MinHeap)malloc(sizeof (struct HeapStruct));
H->arr = (int*)malloc((maxsize + 1) * sizeof(int));
H->size = 0;
H->capacity = maxsize;
H->arr[0] = MinData; // 哨兵,小于所有元素
return H;
}
bool isfull(MinHeap H)