本文整理汇总了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)
})
})
开发者ID:trivial-space,项目名称:libs,代码行数:58,代码来源:heap.test.ts
示例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)
})
开发者ID:trivial-space,项目名称:libs,代码行数:7,代码来源:heap.test.ts
注:本文中的datastructures/heap.Heap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论