Skip to content

Instantly share code, notes, and snippets.

@figengungor
Created October 9, 2013 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save figengungor/6906605 to your computer and use it in GitHub Desktop.
Save figengungor/6906605 to your computer and use it in GitHub Desktop.
Usage of heapq module in Python
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