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);
}

Comments

Posts Quoted:
Reply
Clear All Quotes

About This Project

  • Project ID
    44377
  • Created
    Sep 4, 2012
  • Last Released File
    Sep 4, 2012
  • Total Downloads
    527
  • License

Categories

Members

Recent Files