Quote:
Originally Posted by Gambet
Simple bubble sort algorithm used when sorting data from least to greatest or from greatest to least. Bubble sorting is one of the slowest algorithms for sorting data, but, it's good enough when you have to sort arrays with a small number of data.
Least to Greatest:
Greatest to Least:
|
Both examples are almost the same,
' if (array[b+1] < array[b]) ' is only changing
Nice script tho Gambet
Here is maybe how I would do it
PHP Code:
//#CLIENTSIDE
function onCreated()
{
temp.example = {1,6,4,2, 5,8,20,100,54,1000,523};
doFunction( "GreatestToLast", temp.example);
}
function doFunction( mode, array)
{
for ( temp.a = 0; temp.a < temp.array.size() - 1; temp.a ++)
{
for ( temp.b = 0; temp.b < temp.array.size() - 1 - temp.a; temp.b ++)
{
if ( temp.mode == "GreatestToLast")
{
if ( temp.array[ temp.b + 1] > temp.array[ temp. b])
{
this.temp = temp.array[ temp.b];
temp.array[ temp.b] = temp.array[ temp.b + 1];
temp.array[ temp.b + 1] = this.temp;
this.results = temp.array;
player.chat = this.results;
}
}else
{
if ( temp.mode == "LeastToGreatest")
{
if ( temp.array[ temp.b + 1] < temp.array[ temp.b])
{
this.temp = temp.array[ temp.b];
temp.array[ temp.b] = temp.array[ temp.b + 1];
temp.array[ temp.b + 1] = this.temp;
this.results = temp.array;
player.chat = this.results;
}
}
}
}
}
}