バブルソート
というわけで、本日二回目の更新のお題目は「バブルソート」。
さっと40分ほどで作ってみました。なのでバグがあるかもしれないです。
え? Sortコマンドがある? 気にすんなです。
また、SRC上で無理矢理ソートしているので、かなりの力技になってます。
んで、肝心のソースはこんな感じです。
# babble_sort "配列名" "検索キー(要素orインデックス)" babble_sort: Local temp temp2 i elenum type index target If (ArgNum < 2) or (Args(2) = "要素") Then # 要素でソート type = 1 Else # インデックスでソート type = 2 Endif CopyArray Eval(Args(1)) temp elenum = Count(temp) i = 0 Do while (elenum > i) Incr i target = "" ForEach index In temp If target = "" Then target = index Else If type = 1 Then If StrComp(temp[target],temp[index]) = 1 Then target = index Endif Else If StrComp(target,index) = 1 Then target = index Endif Endif Endif Next temp2[target] = temp[target] UnSet temp[target] Loop CopyArray temp2 Eval(Args(1)) Return