Edit by BB: thread split from here
Edited by Bomb Bloke, 30 August 2017 - 10:05 AM.
Posted 29 August 2017 - 07:39 AM
Edited by Bomb Bloke, 30 August 2017 - 10:05 AM.
Posted 29 August 2017 - 07:49 AM
Xelostar, on 29 August 2017 - 07:39 AM, said:
Posted 29 August 2017 - 10:24 AM
SquidDev, on 29 August 2017 - 07:49 AM, said:
Xelostar, on 29 August 2017 - 07:39 AM, said:
function quickSort(arrayToSort)
local n = table.getn(arrayToSort)
if (n <= 1) then
return arrayToSort
else
local pivot = math.random(1, n)
local pivotValue = arrayToSort[pivot].distance
local smallerArray = {}
local equalArray = {}
local biggerArray = {}
for k, v in pairs(arrayToSort) do
if (v.distance < pivotValue) then
table.insert(smallerArray, v)
elseif (v.distance == pivotValue) then
table.insert(equalArray, v)
else
table.insert(biggerArray, v)
end
end
local sortedSmallerArray = quickSort(smallerArray)
local sortedBiggerArray = quickSort(biggerArray)
local sortedArray = sortedBiggerArray
for k, v in pairs(equalArray) do
table.insert(sortedArray, v)
end
for k, v in pairs(sortedSmallerArray) do
table.insert(sortedArray, v)
end
return sortedArray
end
end
Edited by Xelostar, 29 August 2017 - 10:28 AM.
Posted 29 August 2017 - 10:28 AM
Xelostar, on 29 August 2017 - 10:24 AM, said:
SquidDev, on 29 August 2017 - 07:49 AM, said:
table.sort(arrayToSort, function(x, y) return x.distance < y.distance end)
Edited by SquidDev, 29 August 2017 - 10:29 AM.
Posted 29 August 2017 - 11:19 AM
function compare(x, y) return x.value < y.value end function sort(table) local sorted = table.sort(table, compare) -- < Error here return sorted end
Posted 29 August 2017 - 11:26 AM
Posted 29 August 2017 - 11:58 AM
Posted 29 August 2017 - 05:30 PM
Xelostar, on 29 August 2017 - 11:58 AM, said:
Posted 30 August 2017 - 02:36 AM
Posted 30 August 2017 - 09:44 AM
Bomb Bloke, on 30 August 2017 - 02:36 AM, said:
0 members, 1 guests, 0 anonymous users