View Single Post
  #3  
Old 01-10-2007, 05:21 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Gambet View Post
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:
... 

Greatest to Least:

PHP Code:
... 
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,25,8,20,100,54,1000,523};
  
doFunction"GreatestToLast"temp.example);
}

function 
doFunctionmode, array) 
{
  for ( 
temp.0temp.temp.array.size() - 1temp.++) 
  {
    for ( 
temp.0temp.temp.array.size() - temp.atemp.++) 
    {
      if ( 
temp.mode == "GreatestToLast")
      {
        if ( 
temp.array[ temp.1] > temp.array[ tempb]) 
        {
           
this.temp temp.array[ temp.b];
           
temp.array[ temp.b] = temp.array[ temp.1];
           
temp.array[ temp.1] = this.temp;
           
this.results temp.array;
           
player.chat this.results;
        }
      }else
      {
        if ( 
temp.mode == "LeastToGreatest")
        {
          if ( 
temp.array[ temp.1] < temp.array[ temp.b]) 
          {
             
this.temp temp.array[ temp.b];
             
temp.array[ temp.b] = temp.array[ temp.1];
             
temp.array[ temp.1] = this.temp;
             
this.results temp.array;
             
player.chat this.results;
          }
        }
      }
    }
  }

__________________
Reply With Quote