Skip to content

Commit 5df8478

Browse files
committed
Create search_tree.c
1 parent 094c93b commit 5df8478

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Tree/search_tree.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
typedef struct node
5+
{
6+
int value;
7+
struct node* left;
8+
struct node* right;
9+
} node;
10+
11+
bool search_binary_tree(node*, const int);
12+
13+
bool search_binary_tree(node* tree, const int value)
14+
{
15+
if (tree == NULL)
16+
{
17+
return false;
18+
}
19+
else if (value < tree->value)
20+
{
21+
return search(tree->left, value);
22+
}
23+
else if (value > tree->value)
24+
{
25+
return search(tree->right, value);
26+
}
27+
else if (value == tree->value)
28+
{
29+
return true;
30+
}
31+
else
32+
{
33+
return false;
34+
}
35+
}
36+
37+
int main(void)
38+
{
39+
return 0;
40+
}

0 commit comments

Comments
 (0)