bubble Sort

bubbleSort is an algorithm that easily sorts data from least to greatest. Making a vote system has never been easier! Need a global leaderboard? You can have one in seconds.

  • Threat meters?
    • DPS meters?
      • Who's on top?

No more long, drawn out, complicated and hard to read If-Then-Elses.

Simply call bubbleSort(string) and all of your data will be returned as a string in order from Least to Greatest.

Note that bubbleSort is not meant to order massive amounts of data. The more data entered into bubbleSort, the longer it will take to receive ordered data back. bubbleSort is by far not the most powerful sorting algorithm, it's a simple and easy to implement code and it's meant to be that way.

Simply copy/paste the code into a Custom Script. Call bubbleSort(string) to retrieve information. Data is separated by word in the string, so use simple StringWord() code/triggers to put the information into variables.

string bubbleSort(string lp_list) {   
    int init_data;
//
//
//              VARIABLES
    int BS_itemCount = 1;                   //Number of items in the lp_list
    int TMP_i;                              //Loop Structure
    int TMP_n;                              //Temporary Integer                 
    int TMP_j = 1;                          //Temporary Integer
    fixed[101] BS_data;                     //Holds up to 100 pieces of data (increase size to adjust)
    fixed TMP_dHold;                        //Temporarily Holds old data
    string BS_return;                       //Returned String
    bool BS_swapped = false;                //Indicates whether two items were swapped or not


//
//
//              ARRAYS
    init_data = 0;
    while (init_data <= 100) {
        BS_data[init_data] = 0.0;
        init_data = init_data + 1;
    }
//                                                   
//
//              ACTIONS
    while(TMP_i != StringLength(lp_list)) {
        Wait(0.0, c_timeGame);
        TMP_i = TMP_i + 1;
        if(StringSub(lp_list,TMP_i,TMP_i) == " ") {
            BS_itemCount = BS_itemCount + 1;
        }
    }
    TMP_i = 1;
    while(TMP_i <= BS_itemCount) {
        //Wait(0.0, c_timeGame);
        BS_data[TMP_i] = StringToFixed(StringWord(lp_list,TMP_i));
        TMP_i = TMP_i + 1;
    }
    TMP_n = BS_itemCount;
    while(BS_swapped == false || BS_swapped == true) {
        //Wait(0.0, c_timeGame);
        BS_swapped = false;
        TMP_j = 2;
        while(TMP_j <= TMP_n - 0) {
            //Wait(0.0, c_timeGame);
            if(BS_data[TMP_j-1] > BS_data[TMP_j]) {
                TMP_dHold = BS_data[TMP_j-1];
                BS_data[TMP_j-1] = BS_data[TMP_j];
                BS_data[TMP_j] = TMP_dHold;
                BS_swapped = true;
            }
            TMP_j = TMP_j + 1;
        }
        if(BS_swapped == false) { break; }
        
    }
    TMP_i = 1;
    while(TMP_i <= BS_itemCount) {
        //Wait(0.0, c_timeGame);
        BS_return = BS_return + FixedToString(BS_data[TMP_i], 0) + " ";
        TMP_i = TMP_i + 1;
    }
    BS_return = StringSub(BS_return, 1, StringLength(BS_return) - 1);
    return(BS_return);
}

Download

File Name Status Version Downloads Date
bubbleSort R - 205 04/09/2012
bubble Sort
bubble Sort

Dear youtuber!
Have you a channel youtube and want to bring your Video to quality visitors?
Do you want your video to appear on our website?
Do you want to become partner with us?
Just 3 steps to become our partner:
Step 1: Make video review for mods, addons, plugins, ... which you like
Step 2: Upload this video to youtube and our link to your video description
Step 3: Send the youtube video link via message to http://fb.com/9lifehack or leave a comment in the post. We will add your video in the our post, it will help you have more view.
JOIN to get more youtube view with us!!!!

Related Posts

Smarty Productivity Happiness

9LifeHack.com - make things smart