|
137 | 137 | A = [16, 14, 10, 8, 7, 9, 3, 2, 4, 1] # cf. Figure 6.5, p. 164
|
138 | 138 | max_pq = MaxPQ(A, len(A))
|
139 | 139 | max_pq.build_max_heap()
|
140 |
| -print('\nafter buildMaxHeap:', max_pq.A) |
| 140 | +print('\nafter build_max_heap:', max_pq.A) |
141 | 141 | max_pq.heap_increase_key(8, 15)
|
142 |
| -print('after heapIncreaseKey(4 -> 15):', max_pq.A) |
| 142 | +print('after heap_increase_key(4 -> 15):', max_pq.A) |
143 | 143 |
|
144 | 144 | A = [15, 13, 9, 5, 12, 8, 7, 4, 0, 6, 2, 1] # cf. Exercise 6.5-2, p. 165
|
145 | 145 | max_pq = MaxPQ(A, len(A))
|
146 | 146 | max_pq.build_max_heap()
|
147 |
| -print('\nafter buildMaxHeap:', max_pq.A) |
| 147 | +print('\nafter build_max_heap:', max_pq.A) |
148 | 148 | max_pq.max_heap_insert(10)
|
149 |
| -print('after maxHeapInsert(10):', max_pq.A) |
| 149 | +print('after max_heap_insert(10):', max_pq.A) |
150 | 150 |
|
151 | 151 | # TO-DO: fix heap_delete
|
| 152 | + |
| 153 | +# CLRS Section 6.5 Exercises - Min Priority Queue |
| 154 | +from data_structures.p165_min_pq import MinPQ |
| 155 | +A = [] |
| 156 | + |
| 157 | +print('\nExercise 6.5-3 - Min Priority Queue') |
| 158 | + |
| 159 | +A = [16, 14, 10, 8, 7, 9, 3, 2, 4, 1] # cf. Figure 6.5, p. 164 |
| 160 | +min_pq = MinPQ(A, len(A)) |
| 161 | +min_pq.build_min_heap() |
| 162 | +print('\nafter build_min_heap:', min_pq.A) |
| 163 | +min_pq.heap_decrease_key(8, 15) |
| 164 | +print('after heap_decrease_key(4 -> 15):', min_pq.A) |
| 165 | + |
| 166 | +A = [15, 13, 9, 5, 12, 8, 7, 4, 0, 6, 2, 1] # cf. Exercise 6.5-2, p. 165 |
| 167 | +min_pq = MinPQ(A, len(A)) |
| 168 | +min_pq.build_min_heap() |
| 169 | +print('\nafter build_min_heap:', min_pq.A) |
| 170 | +min_pq.min_heap_insert(10) |
| 171 | +print('after min_heap_insert(10):', min_pq.A) |
0 commit comments