Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

heapq basic push and pop - default minHeap

>>> def heapsort(iterable):
...     h = []
...     for value in iterable:
...         heappush(h, value)
...		# default its min heap
...	    print("Smallest element", h[0])
...     return [heappop(h) for i in range(len(h))]
...
>>> heapsort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Source by docs.python.org #
 
PREVIOUS NEXT
Tagged: #heapq #basic #push #pop #default #minHeap
ADD COMMENT
Topic
Name
4+4 =