本文整理汇总了TypeScript中datastructures/heap.Heap类的典型用法代码示例。如果您正苦于以下问题:TypeScript Heap类的具体用法?TypeScript Heap怎么用?TypeScript Heap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Heap类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('maxHeap', function() {
let heap: Heap<N>
beforeEach(function() {
heap = createHeap(numericalCompare)
})
it('is initially empty', function() {
expect(heap.size()).toBe(0)
})
it('can be created from an array', function() {
heap.fromArray([1, 2, 3])
expect(heap.size()).toBe(3)
})
it('can be inspect the highest value', function() {
heap.fromArray([1, 3, 2])
expect(heap.getTop()).toBe(3)
expect(heap.size()).toBe(3)
})
it('returns the biggest item by pulling', function() {
heap.fromArray([2, 4, 3, 1])
expect(heap.size()).toBe(4)
expect(heap.pull()).toBe(4)
expect(heap.size()).toBe(3)
expect(heap.pull()).toBe(3)
expect(heap.size()).toBe(2)
expect(heap.pull()).toBe(2)
expect(heap.size()).toBe(1)
expect(heap.pull()).toBe(1)
expect(heap.size()).toBe(0)
})
it('can insert new elements', function() {
heap.fromArray([3, 6])
heap.insert(5)
heap.insert(10)
expect(heap.pull()).toBe(10)
expect(heap.pull()).toBe(6)
expect(heap.pull()).toBe(5)
expect(heap.pull()).toBe(3)
})
it('returns undefined on pulling on empty heap', function() {
expect(heap.pull()).toBeUndefined
expect(heap.pull()).toBeUndefined
expect(heap.pull()).toBeUndefined
expect(heap.size()).toBe(0)
})
})
示例2: function
it('returns undefined on pulling on empty heap', function() {
expect(heap.pull()).toBeUndefined
expect(heap.pull()).toBeUndefined
expect(heap.pull()).toBeUndefined
expect(heap.size()).toBe(0)
})