Created
October 9, 2013 19:14
-
-
Save figengungor/6906605 to your computer and use it in GitHub Desktop.
Usage of heapq module in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from heapq import * | |
heapC=[4,5,1,3] | |
print("our candidate random array who volunteered to be a heap array:\n") | |
print(heapC,"\n") | |
heapify(heapC) | |
print("after sorting our candidate as heap: \n") | |
print(heapC,"\n") | |
heappush(heapC, 2) | |
print("after adding 2 to the heap: \n") | |
print(heapC,"\n") | |
heappop(heapC) | |
print("after popping the first element from the heap: \n") | |
print(heapC,"\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment