1. Are you planning to upload your awesome SC2 resource to Hive? Please review the rules here.
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  5. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  6. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  7. The results are out! Check them out.
    Dismiss Notice
  8. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  9. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  10. 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,335
    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

    Joined:
    May 6, 2009
    Messages:
    3,595
    Resources:
    10
    Packs:
    1
    Maps:
    8
    Tutorials:
    1
    Resources:
    10
    [​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