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:
PHP Code:
//#CLIENTSIDE
function onCreated()
{
this.example = {1,6,4,2,5,8,20,100,54,1000,523};
LeastToGreatest(this.example);
}
function LeastToGreatest(array)
{
for (a=0; a<array.size()-1; a++)
{
for (b=0; b<array.size()-1-a; b++)
{
if (array[b+1] < array[b])
{
this.temp = array[b];
array[b] = array[b+1];
array[b+1] = this.temp;
this.results = array;
player.chat = this.results;
}
}
}
}
Greatest to Least:
PHP Code:
//#CLIENTSIDE
function onCreated()
{
this.example = {1,6,4,2,5,8,20,100,54,1000,523};
GreatestToLeast(this.example);
}
function GreatestToLeast(array)
{
for (a=0; a<array.size()-1; a++)
{
for (b=0; b<array.size()-1-a; b++)
{
if (array[b+1] > array[b])
{
this.temp = array[b];
array[b] = array[b+1];
array[b+1] = this.temp;
this.results = array;
player.chat = this.results;
}
}
}
}