名前空間
変種
操作

std::qsort

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を非改変
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を変更する
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
操作を仕切る
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)ソート操作
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイナリ検索操作(ソート範囲で)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)操作を設定します
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ヒープ操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小値/最大値操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
数値演算
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
qsort
 
Defined in header <cstdlib>
void qsort( const void *ptr, size_t count, size_t size,
            int (*comp)(const void *, const void *) );
ソートが指定された配列を昇順でptrが指す。配列はsizecountsize要素が含まれています。関数は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.

目次

[編集] パラメータ

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.
The signature of the comparison function should be equivalent to the following:

 int cmp(const void *a, const void *b);

The function must not modify the objects passed to it.

[編集] 値を返します

(なし)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] ノート

配列の要素の型は'些細なタイプでなければならず、そうでなければ動作は未定義です.
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.

[編集]

次のコードをソート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.

#include <iostream>
#include <cstdlib>
 
int compare_ints(const void* a, const void* b)   // comparison function
{
    int* arg1 = (int*) a;
    int* arg2 = (int*) b;
    if (*arg1 < *arg2) return -1;
    else if (*arg1 == *arg2) return 0;
    else return 1;
}
 
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';
}

Output:

-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.

(機能) [edit]
昇順にソートする範囲
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.

(関数テンプレート) [edit]
タイプかどうかをチェックするには、ささいなことです
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.

(クラステンプレート) [edit]
C documentation for qsort