Google

Go to the first, previous, next, last section, table of contents.


qsort

qsort(array[,func])
:: 一次元配列 array をソートする.
return
array (入力と同じ; 要素のみ入れ替わる)
array
一次元配列
func
比較用関数
  • 一次元配列を quick sort でソートする.
  • 比較用関数が指定されていない場合, オブジェクトどうしの比較結果で 順序が下のものから順に並べ換えられる.
  • 0, 1, -1 を返す 2 引数関数が func として与えられた場合, func(A,B)=1 の場合に A<B として, 順序が下の ものから順に並べ換えられる.
  • 配列は新たに生成されず, 引数の配列の要素のみ入れ替わる.
[0] qsort(newvect(10,[1,4,6,7,3,2,9,6,0,-1]));
[ -1 0 1 2 3 4 6 6 7 9 ]
[1] def rev(A,B) { return A>B?-1:(A<B?1:0); }
[2] qsort(newvect(10,[1,4,6,7,3,2,9,6,0,-1]),rev);
[ 9 7 6 6 4 3 2 1 0 -1 ]
参照
section ord, section vars.


Go to the first, previous, next, last section, table of contents.