Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit070042a

Browse files
committed
Update search_tree.c
1 parent5df8478 commit070042a

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

‎Tree/search_tree.c‎

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
1+
/**
2+
* @file search_tree.c
3+
* @author Xuhua Huang
4+
* @brief Binary search tree implementation
5+
* @version 0.1
6+
* @date 2025-06-08
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
112
#include<stdio.h>
213
#include<stdlib.h>
14+
#include<stdbool.h>
315

4-
typedefstructnode
5-
{
16+
typedefstructnode {
617
intvalue;
718
structnode*left;
819
structnode*right;
920
}node;
1021

11-
boolsearch_binary_tree(node*,constint);
12-
13-
boolsearch_binary_tree(node*tree,constintvalue)
14-
{
15-
if (tree==NULL)
16-
{
22+
/**
23+
* @brief Recursively searches for a value in a binary search tree (BST).
24+
* Assumes the BST property: left < root < right.
25+
*
26+
* @param root Pointer to the root node of the tree.
27+
* @param target The value to search for.
28+
* @return true if the value is found, false otherwise.
29+
*/
30+
boolsearch_binary_tree(node*tree,constintvalue) {
31+
if (tree==NULL) {
1732
return false;
18-
}
19-
elseif (value<tree->value)
20-
{
21-
returnsearch(tree->left,value);
22-
}
23-
elseif (value>tree->value)
24-
{
25-
returnsearch(tree->right,value);
26-
}
27-
elseif (value==tree->value)
28-
{
33+
}elseif (value<tree->value) {
34+
returnsearch_binary_tree(tree->left,value);
35+
}elseif (value>tree->value) {
36+
returnsearch_binary_tree(tree->right,value);
37+
}elseif (value==tree->value) {
2938
return true;
30-
}
31-
else
32-
{
39+
}else {
3340
return false;
3441
}
3542
}
3643

37-
intmain(void)
38-
{
44+
intmain(void) {
3945
return0;
4046
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp