Sort List of Types

Blitz3D Forums/Blitz3D Beginners Area/Sort List of Types

Tibit(Posted 2004) [#1]
What is the most effective (fastest) and simplest way to sort a series of types by a field. Like players after their ID% or name$.


soja(Posted 2004) [#2]
One approach that is both clean and effective is to sort on insertion--that is, when you create the object. Just run through the list until you find out where it's supposed to go, then use Insert and Before or After. This can be optimised if you know certain things about your data.

If you don't have the data when you create you object, you can still use Insert and Before/After to move the type objects. Look up different sort algorithms.

If you don't want to always be reordering your Type list, you can create an array will the same number of elements as type objects and store references to each object according to what order they should be in, like this:

myArray.mytype[4]
myArray[0]=b
myArray[1]=a
myArray[2]=d
myArray[3]=c

mytype list
a.mytype name2
b.mytype name1
c.mytype name4
d.mytype name3