2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -6,13 +6,10 @@ function quicksort(t, start, endi)
|
|||
local pivot = start
|
||||
for i = start + 1, endi do
|
||||
if t[i] <= t[pivot] then
|
||||
local temp = t[pivot + 1]
|
||||
t[pivot + 1] = t[pivot]
|
||||
if(i == pivot + 1) then
|
||||
t[pivot] = temp
|
||||
if i == pivot + 1 then
|
||||
t[pivot],t[pivot+1] = t[pivot+1],t[pivot]
|
||||
else
|
||||
t[pivot] = t[i]
|
||||
t[i] = temp
|
||||
t[pivot],t[pivot+1],t[i] = t[i],t[pivot],t[pivot+1]
|
||||
end
|
||||
pivot = pivot + 1
|
||||
end
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
function quicksort(t)
|
||||
if #t<2 then return t end
|
||||
local pivot=t[1]
|
||||
local a,b,c={},{},{}
|
||||
for _,v in ipairs(t) do
|
||||
if v<pivot then a[#a+1]=v
|
||||
elseif v>pivot then c[#c+1]=v
|
||||
else b[#b+1]=v
|
||||
end
|
||||
end
|
||||
a=quicksort(a)
|
||||
c=quicksort(c)
|
||||
for _,v in ipairs(b) do a[#a+1]=v end
|
||||
for _,v in ipairs(c) do a[#a+1]=v end
|
||||
return a
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue