107w-heap

1.0.0 • Public • Published

安装

npm install 107w-heap

导入

const Heap = require('107w-heap')

实例

const Heap = require('107w-heap')
// 默认最小堆
const heap = new Heap()
const arr = [5, 4, 3, 2, 1, 0]
const res = []
for(let item of arr) {
  heap.insert(item)
}
while(heap.count) {
  res.push(heap.delMax())
}
// res [0,1,2,3,4,5]

方法 & 属性

// 向堆插入元素
heap.insert()

// 删除并返回堆顶元素
heap.delMax()

// 堆元素个数
heap.count

// 创建堆实例,可以传参自定义比较回调函数,默认创建最小堆
// 创建最大堆
new Heap(function(i, j) {return this.heap[i] < this.heap[j];})

开源协议

ISC

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    6
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    6

Package Sidebar

Install

npm i 107w-heap

Weekly Downloads

6

Version

1.0.0

License

ISC

Unpacked Size

2.45 kB

Total Files

3

Last publish

Collaborators

  • 107w