Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,39 @@
|
|||
function siftDown(sequence arr, integer s, integer last)
|
||||
integer root = s
|
||||
while root*2<=last do
|
||||
integer child = root*2
|
||||
if child<last and arr[child]<arr[child+1] then
|
||||
child += 1
|
||||
end if
|
||||
if arr[root]>=arr[child] then exit end if
|
||||
object tmp = arr[root]
|
||||
arr[root] = arr[child]
|
||||
arr[child] = tmp
|
||||
root = child
|
||||
end while
|
||||
return arr
|
||||
end function
|
||||
|
||||
function heapify(sequence arr, integer count)
|
||||
integer s = floor(count/2)
|
||||
while s>0 do
|
||||
arr = siftDown(arr,s,count)
|
||||
s -= 1
|
||||
end while
|
||||
return arr
|
||||
end function
|
||||
|
||||
function heap_sort(sequence arr)
|
||||
integer last = length(arr)
|
||||
arr = heapify(arr,last)
|
||||
while last>1 do
|
||||
object tmp = arr[1]
|
||||
arr[1] = arr[last]
|
||||
arr[last] = tmp
|
||||
last -= 1
|
||||
arr = siftDown(arr,1,last)
|
||||
end while
|
||||
return arr
|
||||
end function
|
||||
|
||||
?heap_sort({5,"oranges","and",3,"apples"})
|
||||
Loading…
Add table
Add a link
Reference in a new issue