Message388013
Heaps are not sorted lists! It is true that a sorted list is a heap, but heaps are not necessarily sorted.
Here is another heap which is not sorted:
>>> L = []
>>> for n in (9, 7, 8, 11, 4):
... heapq.heappush(L, n)
...
>>> L
[4, 7, 8, 11, 9]
https://en.wikipedia.org/wiki/Heap_(data_structure)
Also:
>>> L = [9, 8, 7, 2, 3, 5, 4, 1, 0, 6]
>>> heapq.heapify(L)
>>> L
[0, 1, 4, 2, 3, 5, 7, 8, 9, 6]
If we change the order of the initial values, the heap changes too:
>>> L = [9, 8, 7, 2, 3, 5, 4, 1, 0, 6]
>>> L.reverse()
>>> heapq.heapify(L)
>>> L
[0, 4, 1, 6, 5, 3, 2, 7, 8, 9] |
|
Date |
User |
Action |
Args |
2021-03-03 11:15:32 | steven.daprano | set | recipients:
+ steven.daprano, mike.koikos |
2021-03-03 11:15:32 | steven.daprano | set | messageid: <1614770132.66.0.782794591437.issue43385@roundup.psfhosted.org> |
2021-03-03 11:15:32 | steven.daprano | link | issue43385 messages |
2021-03-03 11:15:32 | steven.daprano | create | |
|