Last active
November 18, 2021 01:03
-
-
Save ochilab/0728ab7196ce8c8be25ac9bcaff3fa6b to your computer and use it in GitHub Desktop.
二分探索木の検索処理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct bNode{ | |
int point; | |
struct bNode *left; | |
struct bNode *right; | |
}; | |
struct bNode *binSearchNode(struct bNode *root, int point){ | |
struct bNode *node; | |
node = root; //ルートの位置をスタートとする | |
while(node!=NULL){ | |
if(point < node->point){ // 探索値がノードの値よりも小さい場合 | |
node = node->left; //左へ | |
} else if(point > node->point){ //探索値がノードの値よりも大きい場合 | |
node = node->right; //右へ | |
} else { //それ以外(同じ=みつかったということ) | |
return node; | |
} | |
} | |
return NULL;// ここに来るということは見つからなかったということ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment