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