Current collected state Current
Observed since 20 Oct, 18:00 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
提供js堆排序(优先级队列)数据结构
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
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 1.0.0Registry latest | 9 Oct 2022 | 0 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 18:00 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:b1d620a3fdd7a75af29cf87751b3fb86791fc838199ca523320e19854c25e4e8