std::qsort
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
Defined in header <cstdlib> | ||
void qsort(constvoid*ptr, size_t count, size_t size, int(*comp)(constvoid*, constvoid*)); | ||
ソートが指定された配列を昇順で
ptr
が指す。配列はsizecount
のsize
要素が含まれています。関数はcomp
がオブジェクトの比較に使用される、によって指さ.Original:
Sorts the given array pointed to by
ptr
in ascending order. The array contains count
elements of size size
. Function pointed to by comp
is used for object comparison.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集]パラメータ
ptr | - | ソートする配列へのポインタ Original: pointer to the array to sort The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
count | - | 配列内の要素の数 Original: number of element in the array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
size | - | バイト単位で配列内の各要素の大きさ Original: size of each element in the array in bytes The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
comp | - | comparison function which returns a negative integer value if the first argument is less than the second, a positive integer value if the first argument is greater than the second and zero if the arguments are equal. int cmp(constvoid*a, constvoid*b); The function must not modify the objects passed to it. |
[編集]値を返します
(なし)
[編集]ノート
配列の要素の型は'些細なタイプでなければならず、そうでなければ動作は未定義です.
Original:
The type of the elements of the array must be a trivial type, otherwise the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集]例
次のコードをソート
qsort()
を使用して整数の配列. Original:
The following code sorts an array of integers using
qsort()
. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
このコードを実行します
#include <iostream>#include <cstdlib> int compare_ints(constvoid* a, constvoid* b)// comparison function{int* arg1 =(int*) a;int* arg2 =(int*) b;if(*arg1 <*arg2)return-1;elseif(*arg1 ==*arg2)return0;elsereturn1;} int main(){int a[]={-2, 99, 0, -743, 2, 3, 4};int size =7; std::qsort(a, size, sizeof(int), compare_ints); for(int i =0; i < size; i++){std::cout<< a[i]<<" ";}std::cout<<'\n';}
出力:
-743 -2 0 2 3 4 99
[編集]参照
不特定の型の要素の配列を検索します Original: searches an array for an element of unspecified type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数) | |
昇順にソートする範囲 Original: sorts a range into ascending order The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (関数テンプレート) | |
(C++11) | タイプかどうかをチェックするには、ささいなことです Original: checks if a type is trivial The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (クラステンプレート) |
C documentation for qsort |