2011-09-30 105 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?它甚至允许你提供一个功能来做比较。