@@ -0,0 +1,1581 @@
+class BinHeap:%0A    def __init__(self):%0A        self.heapList = %5B0%5D%0A        self.currentSize = 0%0A%0A%0A    def percUp(self,i):%0A        while i // 2 %3E 0:%0A          if self.heapList%5Bi%5D %3C self.heapList%5Bi // 2%5D:%0A             tmp = self.heapList%5Bi // 2%5D%0A             self.heapList%5Bi // 2%5D = self.heapList%5Bi%5D%0A             self.heapList%5Bi%5D = tmp%0A          i = i // 2%0A%0A    def insert(self,k):%0A      self.heapList.append(k)%0A      self.currentSize = self.currentSize + 1%0A      self.percUp(self.currentSize)%0A%0A    def percDown(self,i):%0A      while (i * 2) %3C= self.currentSize:%0A          mc = self.minChild(i)%0A          if self.heapList%5Bi%5D %3E self.heapList%5Bmc%5D:%0A              tmp = self.heapList%5Bi%5D%0A              self.heapList%5Bi%5D = self.heapList%5Bmc%5D%0A              self.heapList%5Bmc%5D = tmp%0A          i = mc%0A%0A    def minChild(self,i):%0A      if i * 2 + 1 %3E self.currentSize:%0A          return i * 2%0A      else:%0A          if self.heapList%5Bi*2%5D %3C self.heapList%5Bi*2+1%5D:%0A              return i * 2%0A          else:%0A              return i * 2 + 1%0A%0A    def delMin(self):%0A      retval = self.heapList%5B1%5D%0A      self.heapList%5B1%5D = self.heapList%5Bself.currentSize%5D%0A      self.currentSize = self.currentSize - 1%0A      self.heapList.pop()%0A      self.percDown(1)%0A      return retval%0A%0A    def buildHeap(self,alist):%0A      i = len(alist) // 2%0A      self.currentSize = len(alist)%0A      self.heapList = %5B0%5D + alist%5B:%5D%0A      while (i %3E 0):%0A          self.percDown(i)%0A          i = i - 1%0A%0Abh = BinHeap()%0Abh.buildHeap(%5B9,5,6,2,3%5D)%0A%0Aprint(bh.delMin())%0Aprint(bh.delMin())%0Aprint(bh.delMin())%0Aprint(bh.delMin())%0Aprint(bh.delMin())%0A

Create binary_heap.py