alias sort {
tokenize 32 $$1-
var %s = $1
var %hname = $+(asort.,$ticks)
if ($hget(%hname)) hfree %hname
var %i = 0, %ii = $len(%s)
while (%i < %ii) {
inc %i
hadd -m %hname $+(s.,%i) $asc($mid(%s,%i,1))
}
var %x, %i = 0, %ii = $calc($len(%s) - 1)
while (%i < %ii) {
inc %i
%x = %i
var %j = %i, %jj = $calc(%ii + 1)
while (%j < %jj) {
inc %j
if ($hget(%hname,$+(s.,%x)) >= $hget(%hname,$+(s.,%j))) { %x = %j }
}
var %t = $hget(%hname,$+(s.,%i))
hadd %hname $+(s.,%i) $hget(%hname,$+(s.,%x))
hadd %hname $+(s.,%x) %t
}
var %ss, %i = 0, %ii = $len(%s)
while (%i < %ii) {
inc %i
%ss = $+(%ss,$chr($hget(%hname,$+(s.,%i))))
}
$iif($isid,return,echo -a) %ss
hfree %hname
}