1. Are you planning to upload your awesome SC2 resource to Hive? Please review the rules here.
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. Shoot to thrill, play to kill. Sate your hunger with the 33rd Modeling Contest!
    Dismiss Notice
  8. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Bubble Sort

Submitted by Sube2
This bundle is marked as approved. It works and satisfies the submission rules.
Bubble Sort is an algorithm used for ordering data from least to greatest.
Lot's of modders avoid making things that need sorted because it seems complicated at first. It's not that bad.

this Bubble Sort algorithm uses NO global variables, so all you need to do is copy/paste the code into your map.

The return is a string. the string will separate each piece of data by word.
(Ex. 10 20 30 40 . . .) So to use the sorted data in a trigger, all you need to do is understand very basic String conversion triggering.

You will have to use a Custom Script to use this algorithm.
If you're not very fluent, or not fluent at all with Galaxy, no worries.

Simply go to Actions and find Custom Script. This action will allow you to run a simple line of code.

Create a local variable of type string in your trigger.

then inside the script type lv_VariableName = bubbleSort(string)

this will run the code and return the data in order from least to greatest.


Here is the code:

Code (Text):
string bubbleSort(string lp_list) {   // Greatest to Least
    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[31] BS_data;                      //Holds up to 31 pieces of data
    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 <= 30) {
        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);
}

Keywords:
bubble sort algorithm least to greatest order numbers data sorted leaderboard global board
Contents

bubbleSortTest.SC2Map (Map)

Reviews
Moderator
17:55, 31st May 2016 [IMG][c] System: Bubble Sort Review by Shar Dundred This is a very simple system, but it appears to be working properly. Not rated Approved
  1. 17:55, 31st May 2016
    [​IMG]
    Review

    System: Bubble Sort


    Review
    by Shar Dundred


    This is a very simple system, but it appears to be working properly.

    Not rated
    Approved

     
  2. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    wtf... are you serious?

    I vote for immediate rejection, lol.
     
  3. Sube2

    Sube2

    Joined:
    Jul 17, 2007
    Messages:
    139
    Resources:
    9
    Maps:
    7
    StarCraft II Resources:
    2
    Resources:
    9
    I'm going to assume... You don't know what Bubble Sort is >.>.

    Bubble Sort is one of the most simplistic forms of sorting.
    I used bubble sort because I only need to sort 8 reals in my map. No reason to do heap sort or merge sort just for that.

    If you need to sort over 50 pieces of data (frequently that is) I wouldn't suggest using this.

    But... anyone who can use Google should know this, right?
     
  4. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,146
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Code (Text):

    string bubbleSort(string lp_list)
     
    you are using strings... your string parsing is going to be slower than the sorting itself >.<.


    also, qsort is pretty lightweight ; \.

    you can also use qsort + heap sort -> http://en.wikipedia.org/wiki/Introsort, but the heap sort will have a bit of overhead to it.
     
  5. Statharas

    Statharas

    Joined:
    Jul 9, 2008
    Messages:
    2,332
    Resources:
    14
    Tools:
    1
    StarCraft II Resources:
    5
    Tutorials:
    8
    Resources:
    14
    I just laughed my ass off. Nestharius posted resources which nobody besides actual programmers can use. And he complains about this. Which I can actually understand.
     
  6. Shar Dundred

    Shar Dundred

    Map Moderator

    Joined:
    May 6, 2009
    Messages:
    4,408
    Resources:
    12
    Packs:
    1
    Maps:
    10
    Tutorials:
    1
    Resources:
    12
    [​IMG]
    Review

    System: Bubble Sort


    Review
    by Shar Dundred


    This is a very simple system, but it appears to be working properly.

    Not rated
    Approved