「c/algorithm/bsearch」の版間の差分
提供: cppreference.com
細 (r2.7.3) (ロボットによる 追加: de, en, es, fr, it, pt, ru, zh) |
細 (Use {{lc}}. Update links. Various fixes.) |
||
2行: | 2行: | ||
{{c/title|bsearch}} | {{c/title|bsearch}} | ||
{{c/algorithm/navbar}} | {{c/algorithm/navbar}} | ||
− | {{ | + | {{begin}} |
− | {{ | + | {{header | stdlib.h}} |
− | {{ | + | {{| |
void* bsearch( const void* key, const void* ptr, size_t count, size_t size, | void* bsearch( const void* key, const void* ptr, size_t count, size_t size, | ||
int (*comp)(const void*, const void*) ); | int (*comp)(const void*, const void*) ); | ||
}} | }} | ||
− | {{ | + | {{end}} |
{{tr|{{tt|key}}が指す配列内{{tt|ptr}}が指す要素に等しい要素を検索します。配列はsize{{tt|count}}の{{tt|size}}要素が含まれています。関数は{{tt|comp}}がオブジェクトの比較に使用される、によって指さ.|Finds an element equal to element pointed to by {{tt|key}} in an array pointed to by {{tt|ptr}}. The array contains {{tt|count}} elements of size {{tt|size}}. Function pointed to by {{tt|comp}} is used for object comparison.}} | {{tr|{{tt|key}}が指す配列内{{tt|ptr}}が指す要素に等しい要素を検索します。配列はsize{{tt|count}}の{{tt|size}}要素が含まれています。関数は{{tt|comp}}がオブジェクトの比較に使用される、によって指さ.|Finds an element equal to element pointed to by {{tt|key}} in an array pointed to by {{tt|ptr}}. The array contains {{tt|count}} elements of size {{tt|size}}. Function pointed to by {{tt|comp}} is used for object comparison.}} | ||
===パラメータ=== | ===パラメータ=== | ||
− | {{ | + | {{begin}} |
− | {{ | + | {{| key |{{tr| を検索するための要素へのポインタ| pointer to the element to search for}}}} |
− | {{ | + | {{| ptr |{{tr| 検討する配列へのポインタ| pointer to the array to examine}}}} |
− | {{ | + | {{| count |{{tr| 配列内の要素の数| number of element in the array}}}} |
− | {{ | + | {{| size |{{tr| バイト単位で配列内の各要素の大きさ| size of each element in the array in bytes}}}} |
− | {{ | + | {{ccmp | comp | {{tt|key}} is passed as the first argument, an element from the array as the second.}} |
− | {{ | + | {{end}} |
===値を返します=== | ===値を返します=== | ||
− | {{tr|見つかった要素または別の方法で{{ | + | {{tr|見つかった要素または別の方法で{{|NULL}}へのポインタ..|pointer to the found element or {{|NULL}} otherwise.}} |
===例=== | ===例=== | ||
60行: | 60行: | ||
===も参照してください=== | ===も参照してください=== | ||
− | {{ | + | {{begin}} |
− | {{ | + | {{| c/algorithm/qsort}} |
− | {{ | + | {{see cpp | cpp/algorithm/bsearch}} |
− | {{ | + | {{end}} |
[[de:c/algorithm/bsearch]] | [[de:c/algorithm/bsearch]] |
2013年7月2日 (火) 10:04時点における版
![]() |
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
ヘッダ <stdlib.h> で定義
|
||
key
が指す配列内ptr
が指す要素に等しい要素を検索します。配列はsizecount
のsize
要素が含まれています。関数はcomp
がオブジェクトの比較に使用される、によって指さ.Original:
Finds an element equal to element pointed to by
key
in an array pointed to by ptr
. 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.
目次 |
パラメータ
key | - | を検索するための要素へのポインタ
Original: pointer to the element to search for 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 examine 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 | - | 第1引数が第2引数より小さい場合は負の整数値、第1引数が第2引数より大きい場合は正の整数値、第1引数と第2引数が同等な場合はゼロを返す比較関数。 key is passed as the first argument, an element from the array as the second.比較関数のシグネチャは以下と同等であるべきです。 int cmp(const void *a, const void *b); 関数は渡されたオブジェクトを変更してはならず、同じオブジェクトに対してはその配列内の位置にかかわらず一貫した結果を返さなければなりません。 |
値を返します
見つかった要素または別の方法でNULLへのポインタ..
Original:
pointer to the found element or NULL otherwise.
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.
例
Run this code
#include <stdlib.h> #include <stdio.h> struct data { int nr; char const *value; } dat[] = { {1, "Foo"}, {2, "Bar"}, {3, "Hello"}, {4, "World"} }; int data_cmp(void const *lhs, void const *rhs) { struct data const *const l = lhs; struct data const *const r = rhs; return l->nr < r->nr; } int main(void) { struct data key = { .nr = 3 }; struct data const *res = bsearch(&key, dat, sizeof(dat)/sizeof(dat[0]), sizeof(dat[0]), data_cmp); if(!res) { printf("No %d not found\n", key.nr); } else { printf("No %d: %s\n", res->nr, res->value); } }
出力:
No 3: Hello
も参照してください
(C11) |
不特定の型の要素の範囲をソートします (関数) |
bsearch の C++リファレンス
|