std::bsearch
提供: cppreference.com
![]() | このページは、Google 翻訳を使って英語版から機械翻訳されました。 翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
Defined in header <cstdlib> | ||
void* bsearch(constvoid* key, constvoid* ptr, size_t count, size_t size, int(*comp)(constvoid*, constvoid*)); | ||
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 | - | 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. |
[編集]値を返します
見つかった要素または別の方法で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.
[編集]例
このコードを実行します
#include <cstdlib>#include <iostream> int compare(constvoid*ap, constvoid*bp){constint*a =(int*) ap;constint*b =(int*) bp;return*a -*b;} int show_ptr(int*p){if(p ==NULL){std::cout<<"NULL\n";}else{std::cout<< p1 <<' '<<*p1 <<'\n';}} int main(int argc, char**argv){constint ARR_SIZE =8;int arr[ARR_SIZE]={1, 2, 3, 4, 5, 6, 7, 8}; int key1 =4;int*p1 =(int*) std::bsearch(&key1, arr, ARR_SIZE, sizeof(arr[0]), compare); int key2 =9;int*p2 =(int*) std::bsearch(&key2, arr, ARR_SIZE, sizeof(arr[0]), compare); std::cout<<"p1: "; show_ptr(p1); std::cout<<"p2: "; show_ptr(p2);}
出力:
p1: 0xbf9a4c88 4 p2: NULL
[編集]参照
ソートされていない型を持つ要素の範囲 Original: sorts a range of elements with 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: returns range of elements matching a specific key 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 bsearch |