Quicksort for ShiVa3D

If you ever need to sort a table of numbers in shiva, I adapted this Rosetta Code entry for shiva.

The following code:

local tTest = table.newInstance ( )
table.add ( tTest, 1)
table.add ( tTest, 9)
table.add ( tTest, 7)
table.add ( tTest, 3)
table.add ( tTest, 5)
table.add ( tTest, 10)
table.add ( tTest, 6)
table.add ( tTest, -5)
table.add ( tTest, -9)
table.add ( tTest, -15)
table.add ( tTest, 33)
table.add ( tTest, 4)
table.add ( tTest, 8)

this.quicksort (tTest)
for i = 0, table.getSize ( tTest) - 1 do
    log.message ( table.getAt ( tTest, i ) )
end

Produces the output:

-15
-9
-5
1
3
4
5
6
7
8
9
10
33
Published 10 February 2014
blog comments powered by Disqus ~