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,30 @@
|
|||
function quick_sort(sequence x)
|
||||
--
|
||||
-- put x into ascending order using recursive quick sort
|
||||
--
|
||||
integer n, last, mid
|
||||
object xi, midval
|
||||
|
||||
n = length(x)
|
||||
if n<2 then
|
||||
return x -- already sorted (trivial case)
|
||||
end if
|
||||
|
||||
mid = floor((n+1)/2)
|
||||
midval = x[mid]
|
||||
x[mid] = x[1]
|
||||
|
||||
last = 1
|
||||
for i=2 to n do
|
||||
xi = x[i]
|
||||
if xi<midval then
|
||||
last += 1
|
||||
x[i] = x[last]
|
||||
x[last] = xi
|
||||
end if
|
||||
end for
|
||||
|
||||
return quick_sort(x[2..last]) & {midval} & quick_sort(x[last+1..n])
|
||||
end function
|
||||
|
||||
?quick_sort({5,"oranges","and",3,"apples"})
|
||||
Loading…
Add table
Add a link
Reference in a new issue