2011-09-30 103 views
-1

我試圖找出一些數據的中位數,模式,平均值和範圍。使用編程很容易找到意思;但中位數,模式和範圍要求數字按順序排列(從最小到最大)。訂單號與Lua

此外,我試圖組裝它,因此它會返回我需要製作盒子和晶須圖的數據。 (並非全部,只是基本)。

現在我只是在做這個: 順序的編號爲表(函數將返回)

QWERTYUIOP [] \

好了,這裏的主要問題: 將如何我這樣做?

這是我上運行:

function Order_Numbers(Data_Set, Greatest_Integer, Least_Integer) 
local Ordered = {} --Give a place for the numbers to go 
for i=Least_Integer, Greatest_Integer do --Start from the lowest value, continue to highest. 
table.insert(Ordered, Data_Set[i]) 
end 
return Ordered 
end 

但它不工作! 任何人有想法?

回答

1
The Lua distribution includes sort.lua which has a simple implementation of quick sort; slightly simplified, the core is as follows: 

function qsort(vec, low, high) 
    if low < high then 
    local middle = partition(vec, low, high) 
    qsort(vec, low, middle-1) 
    qsort(vec, middle+1, high) 
    end 
end 

- >http://lua-users.org/wiki/LazySort

+0

這將是超級有用的, '>嘗試調用全局「分區」(一個零值)' – John

1

如果你能在地方進行排序,使用table.sort(Data_Set)

5

您是否考慮過使用table.sort?它甚至允許你提供一個功能來做比較。