Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-10-2007, 03:54 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Sorting Data: Bubble Sort

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=0a<array.size()-1a++) 
  {
    for (
b=0b<array.size()-1-ab++) 
    {
      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=0a<array.size()-1a++) 
  {
    for (
b=0b<array.size()-1-ab++) 
    {
      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;
      }
    }
  }


Last edited by Gambet; 01-10-2007 at 05:00 AM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:09 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.