 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
danabnormal
Joined: 09 May 2006 Posts: 1
|
Posted: Tue May 09, 2006 4:04 am Post subject: Sorting arrays |
|
|
Hi chaps!
I'm just thinking about my next project all possibles require one basic function - sorting arrays.
Is there a built in command for sorting or querying arrays, or do you rely on custom built procedures for this?
Thanks!
danabnormal |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Tue May 09, 2006 7:47 am Post subject: |
|
|
Table.sort(table, function (a, b) return a > b end)
http://www.lua.org/manual/5.0/manual.html#2.5.6
| Quote: | table.sort (table [, comp])
Sorts table elements in a given order, in-place, from table[1] to table[n], where n is the size of the table (see 5.4). If comp is given, then it must be a function that receives two table elements, and returns true when the first is less than the second (so that not comp(a[i+1],a[i]) will be true after the sort). If comp is not given, then the standard Lua operator < is used instead.
The sort algorithm is not stable, that is, elements considered equal by the given order may have their relative positions changed by the sort. |
A tutorial can be found here http://www.wowwiki.com/HOWTO:_Do_Tricks_With_Tables
on how to do tricks with tables. Example Table.sort
When you sort the table. Do not index the table. Example of what to do.
| Code: |
array = {
{ stuff here },
{ stuff here },
{ stuff here },
{ stuff here },
{ stuff here },
}
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|