Bubblesort (script)
counter set 0 setvariable % %
setvariable presort {
paramloop: if_1 goto saveparam goto sort saveparam: setvariable a%c% %1 counter add 1 setvariable presort %presort% %1 shift goto paramloop
sort: setvariable presort %presort% } setvariable arraylen %c setvariable i %arraylen
looptest_i: match end_i - match loop_i valid flag put set %i matchwait loop_i:
setvariable j %arraylen looptest_j: match end_j - match loop_j valid flag put set %j matchwait loop_j: setvariable ai %%a%i setvariable aj %%a%j
counter set %ai counter subtract %aj match j_gt_i - match j_eq_i 0 match j_lt_i valid flag put set %c matchwait
j_gt_i:
echo ***SWAP %ai and %aj
setvariable temp %ai setvariable a%i% %aj setvariable a%j% %temp deletevariable temp j_eq_i: j_lt_i:
deletevariable ai deletevariable aj
counter set %j counter subtract 1 setvariable j %c goto looptest_j end_j: deletevariable j counter set %i counter subtract 1 setvariable i %c goto looptest_i end_i: deletevariable i
setvariable i %arraylen setvariable result } looptest_i2: match end_i2 -1 match loop_i2 valid flag put set %i matchwait loop_i2:
setvariable iptr %%a%i% setvariable result %iptr% %result% deletevariable a%i% deletevariable iptr
counter set %i counter subtract 1 setvariable i %c goto looptest_i2 end_i2: setvariable result { %result% echo *** %presort ==> %result
deletevariable presort deletevariable result deletevariable % deletevariable arraylen deletevariable i deletevariable j