Skip to content

Instantly share code, notes, and snippets.

@yywillgist
yywillgist / BinaryHeap.coffee
Created July 25, 2012 14:05
BinaryHeap.coffee
less = (i,j)-> i < j
exchange = (keys,i,j) -> [keys[i],keys[j]] = [keys[j],keys[i]]
swim = (k,keys) ->
exchange(k,k/2) if keys[k] > keys[k/2]
swim(k/2, keys) if k/2 > 1
### need re-thingk sink funtion ###
sink = (k,keys) ->
j = 2*k