// 二叉堆
// 父亲节点大于等于 子节点
// 是一颗完全二叉树
function swap(arr, x, y) {
var temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
class MaxHeap{
constructor(capacity) {
if(arguments.length > 1 ){
// 这是参数是 arr , n
this.capacity = arguments[1];
this.Item = [''].concat(arguments[0])
this.count = arguments[1];
for(var i=Math.floor(this.count/2); i>=1; i--) {
this.shiftDown(i);
}
} else {
this.Item = new Array(capacity+1);;
this.count = 0;
this.capacity = capacity;
}
}
// 返回 数据的大小
size() {
return this.count;
}
// 判断Item是否是 空的
isEmpty() {
return this.count == 0;
}
// 添加新元素