Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
binary_tree
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
florent.didion
binary_tree
Commits
008cbd88
Commit
008cbd88
authored
4 years ago
by
florent.didion
Browse files
Options
Downloads
Patches
Plain Diff
bye black magic
parent
0fecde1b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
binary_tree
+0
-0
0 additions, 0 deletions
binary_tree
binary_tree_lib.c
+24
-14
24 additions, 14 deletions
binary_tree_lib.c
main.c
+3
-1
3 additions, 1 deletion
main.c
with
27 additions
and
15 deletions
binary_tree
+
0
−
0
View file @
008cbd88
No preview for this file type
This diff is collapsed.
Click to expand it.
binary_tree_lib.c
+
24
−
14
View file @
008cbd88
...
...
@@ -17,16 +17,17 @@ node_t *bst_create_node(int val){
}
// détruit l'arbre et vide la mémoire
void
bst_destroy
(
node_t
*
tree
){
if
(
tree
->
left
==
NULL
&&
tree
->
right
==
NULL
){
f
re
e
(
tree
)
;
}
else
if
(
tree
->
left
!=
NULL
){
if
(
tree
==
NULL
){
re
turn
;
}
if
(
tree
->
left
!=
NULL
){
bst_destroy
(
tree
->
left
);
}
else
if
(
tree
->
right
!=
NULL
){
if
(
tree
->
right
!=
NULL
){
bst_destroy
(
tree
->
right
);
}
}
free
(
tree
);
}
// affiche l'arbre (voir plus bas)
void
bst_print
(
node_t
*
tree
,
int
prof
){
...
...
@@ -45,7 +46,7 @@ void bst_print(node_t *tree,int prof){
// insertion de val dans l'arbre et retourne l'arbre (ou NULL si problème)
node_t
*
bst_insert
(
node_t
*
tree
,
int
val
){
if
(
tree
==
NULL
){
tree
=
bst_create_node
(
val
);
tree
=
bst_create_node
(
val
);
}
else
if
(
val
>
tree
->
val
){
if
(
tree
->
right
==
NULL
){
...
...
@@ -63,6 +64,9 @@ node_t *bst_insert(node_t *tree, int val){
bst_insert
(
tree
->
left
,
val
);
}
}
else
{
return
NULL
;
}
return
tree
;
...
...
@@ -131,11 +135,15 @@ bool bst_is_bst(node_t *tree){
// retourne le noeud avec la valeur minimale de l'arbre (NULL s'il y a pas)
node_t
*
bst_find_min_node
(
node_t
*
tree
){
if
(
tree
->
left
!=
NULL
){
bst_find_min_node
(
tree
->
left
);
if
(
tree
==
NULL
){
return
NULL
;
}
else
if
(
tree
->
left
!=
NULL
){
return
bst_find_min_node
(
tree
->
left
);
}
else
{
return
tree
;
}
return
tree
;
}
// retourne la valeur la plus petite stockée dans l'arbre (ou MIN_INT)
...
...
@@ -145,10 +153,12 @@ int bst_find_min(node_t *tree){
// retourne le noeud avec la valeur maximale de l'arbre (NULL s'il y a pas)
node_t
*
bst_find_max_node
(
node_t
*
tree
){
if
(
tree
->
right
!=
NULL
){
bst_find_min_node
(
tree
->
right
);
node_t
*
tree_out
=
tree
;
if
(
tree
->
right
!=
NULL
){
tree_out
=
bst_find_max_node
(
tree
->
right
);
}
return
tree
;
return
tree
_out
;
}
// retourne la valeur la plus grande stockée dans l'arbre (ou MAX_INT)
...
...
This diff is collapsed.
Click to expand it.
main.c
+
3
−
1
View file @
008cbd88
...
...
@@ -15,7 +15,9 @@ int main(){
}
bst_print
(
tree
,
0
);
printf
(
"printed
\n\n
"
);
printf
(
"min value is :%d
\n\n
"
,(
bst_find_min_node
(
tree
))
->
val
);
printf
(
"max value is :%d
\n\n
"
,(
bst_find_max_node
(
tree
))
->
val
);
//bst_print(tree, 0);
bst_destroy
(
tree
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment