1 | # 二项堆 BinomialHeap\<T>
|
2 |
|
3 | 二项堆是是二项树的集合或是由一组二项树组成。二项堆具有良好的性质。在O(logn)的时间内即可完成两个二项堆合并操作,所以二项堆是可合并堆,而仅仅需要O(1)的时间,二项堆即可完成插入操作。因此,基于二项堆实现的优先队列和进程调度算法有着很好的时间性能。同时由于二项树的结构特性和性质,二项树在网络优化等诸多领域也应用广泛。
|
4 | ![BinomialHeap](https://img-blog.csdn.net/20170220094652634)
|
5 |
|
6 | ## 基本操作的API及示例
|
7 | ### 属性
|
8 |
|
9 | #### 节点个数 Count
|
10 | ##### Count:number
|
11 | ``` text
|
12 | 实例:
|
13 | const binomialHeap = new BinomialHeap();
|
14 | const count = BinomialHeap.Count;
|
15 | console.log(count);
|
16 | //0
|
17 | ```
|
18 |
|
19 | #### 头节点 Head
|
20 | ##### Head:LinkNode<HeapNode\<T>>
|
21 | ``` text
|
22 | 实例:
|
23 | const binomialHeap = new BinomialHeap();
|
24 | const head = BinomialHeap.Head;
|
25 | ```
|
26 |
|
27 | ###方法
|
28 |
|
29 | #### 插入 insert
|
30 | ##### insert(value: T):LinkNode<HeapNode\<T>>
|
31 | ``` text
|
32 | 实例:
|
33 | const binomialHeap = new BinomialHeap();
|
34 | const node = binomialHeap.insert(1);
|
35 | console.log(node.Value.value);
|
36 | // 1
|
37 | ```
|
38 |
|
39 | #### 删除最小节点 deleteExtremum
|
40 | ##### deleteExtremum(): T
|
41 | ``` text
|
42 | 实例:
|
43 | const binomialHeap = new BinomialHeap();
|
44 | binomialHeap.insert(3);
|
45 | binomialHeap.insert(1);
|
46 | binomialHeap.insert(2);
|
47 | const value = binomialHeap.deleteExtremum();
|
48 | console.log(value);
|
49 | // 1
|
50 | ```
|
51 |
|
52 | #### 查找最小节点 findExtremum
|
53 | ##### findExtremum(): T
|
54 | ``` text
|
55 | 实例:
|
56 | const binomialHeap = new BinomialHeap();
|
57 | binomialHeap.insert(3);
|
58 | binomialHeap.insert(1);
|
59 | binomialHeap.insert(2);
|
60 | const value = binomialHeap.findExtremum();
|
61 | console.log(value);
|
62 | // 1
|
63 | 描述:
|
64 | 此方法不删除元素
|
65 | ```
|
66 |
|
67 | #### 合并堆 union
|
68 | ##### union(heap: BinomialHeap\<T>): BinomialHeap\<T>
|
69 | ``` text
|
70 | 实例:
|
71 | const binomialHeap = new BinomialHeap();
|
72 | binomialHeap.insert(5);
|
73 | binomialHeap.insert(4);
|
74 | binomialHeap.insert(6);
|
75 | const binomialHeap2 = new BinomialHeap();
|
76 | binomialHeap2.insert(3);
|
77 | binomialHeap2.insert(1);
|
78 | binomialHeap2.insert(2);
|
79 | binomialHeap.union(binomialHeap2);
|
80 | console.log(binomialHeap.Count);
|
81 | // 6
|
82 | console.log(binomialHeap.findExtremum());
|
83 | // 1
|
84 | ```
|
85 |
|
86 | #### 是否为空 isEmpty
|
87 | ##### isEmpty(): boolean
|
88 | ``` text
|
89 | 实例:
|
90 | const binomialHeap = new BinomialHeap();
|
91 | const isEmpty = binomialHeap.isEmpty();
|
92 | console.log(isEmpty);
|
93 | // true
|
94 | ```
|
95 |
|
96 | #### 清空 clear
|
97 | ##### clear(): void
|
98 | ``` text
|
99 | 实例:
|
100 | const binomialHeap = new BinomialHeap();
|
101 | binomialHeap2.insert(3);
|
102 | binomialHeap2.insert(1);
|
103 | binomialHeap2.insert(2);
|
104 | let isEmpty = binomialHeap.isEmpty();
|
105 | console.log(isEmpty);
|
106 | // false
|
107 |
|
108 | binomialHeap.clear();
|
109 | isEmpty = binomialHeap.isEmpty();
|
110 | console.log(isEmpty);
|
111 | // true
|
112 | ``` |
\ | No newline at end of file |