Facebook
From Idiotic Bongo, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 221
  1. def floor(x):
  2.     x
  3. def swap(x, y):
  4.     tmp = tab[x]
  5.     tab[x] = tab[y]
  6.     tab[y] = tmp
  7.  
  8. def heapify(parent):
  9.     L = 2 * parent + 1
  10.     R = 2 * parent + 2
  11.  
  12.     if L > len(tab) - 1:
  13.         return
  14.     elif L == len(tab) - 1:
  15.         aniki = L
  16.     else:
  17.         if tab[L] >= tab[R]:
  18.             aniki = L
  19.         else:
  20.             aniki = R
  21.     if tab[aniki] >= tab[parent]:
  22.         swap(aniki, parent)
  23.         heapify(aniki)
  24.  
  25. tab = [2,1,3,7,1,4,8,8]
  26.  
  27. heapify(0)
  28. print(tab)
  29.  
  30. floor(1.8)