Here is an other alias for nsorttok.It is slow but it shows how to bubble sort an array.It has the same usage as qwerty's one.
Code:
alias nsorttok {
  var %tmp,%x,%y,%k,%n = $numtok($1,$2),%oper,%i = 1
  hmake sort 50
  %tmp = $gettok($1,%i,$2)
  while %tmp { hadd sort %i %tmp  | inc %i | %tmp = $gettok($1,%i,$2) }
  ;perform a bubble sort
  %i = 1
  %oper = $iif($3 = r,<,>)
  while %i < %n {
    %k = 1
    while %k < %n {
      %x = $hget(sort,%k)
      %y = $hget(sort,$calc(%k + 1))
      if %x %oper %y {
        hadd sort %k %y
        hadd sort $calc(%k + 1) %x
      }
      inc %k
    }
    inc %i
  }
  %i = 1
  %tmp =
  while %i <= %n { %tmp = $+(%tmp,$chr($2),$hget(sort,%i)) | inc %i }
  hfree sort
  return %tmp
}