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
7b2fa303
Commit
7b2fa303
authored
4 years ago
by
florent.didion
Browse files
Options
Downloads
Patches
Plain Diff
delete ok
parent
008cbd88
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
+29
-8
29 additions, 8 deletions
binary_tree_lib.c
binary_tree_lib.h
+1
-0
1 addition, 0 deletions
binary_tree_lib.h
with
30 additions
and
8 deletions
binary_tree
+
0
−
0
View file @
7b2fa303
No preview for this file type
This diff is collapsed.
Click to expand it.
binary_tree_lib.c
+
29
−
8
View file @
7b2fa303
...
...
@@ -72,17 +72,38 @@ node_t *bst_insert(node_t *tree, int val){
}
bool
bst_is_empty
(
node_t
*
tree
){
return
NULL
==
tree
;
}
// efface le premier élément contenant la valeur val dans l'arbre
// et retourne l'arbre (ne fait rien si val est absente)
node_t
*
bst_delete
(
node_t
*
tree
,
int
val
){
if
(
val
<
tree
->
val
){
bst_delete
(
tree
->
left
,
val
);
}
else
if
(
val
>
tree
->
val
){
bst_delete
(
tree
->
right
,
val
);
}
if
(
val
==
tree
->
val
){
bst_destroy
(
tree
);
if
(
!
bst_is_empty
(
tree
)){
if
(
val
>
tree
->
val
){
tree
->
right
=
bst_delete
(
tree
->
right
,
val
);
}
else
if
(
val
<
tree
->
val
){
tree
->
left
=
bst_delete
(
tree
->
left
,
val
);
}
else
if
(
tree
->
left
!=
NULL
&&
tree
->
right
!=
NULL
){
node_t
*
next
=
bst_find_max_node
(
tree
->
right
);
tree
->
val
=
next
->
val
;
tree
->
right
=
bst_delete
(
next
,
next
->
val
);
}
else
{
node_t
*
tmp
=
tree
;
if
(
tmp
->
left
!=
NULL
){
tree
=
tree
->
left
;
}
else
if
(
tmp
->
right
!=
NULL
){
tree
=
tree
->
right
;
}
else
{
tree
=
NULL
;
}
free
(
tmp
);
}
}
return
tree
;
}
...
...
This diff is collapsed.
Click to expand it.
binary_tree_lib.h
+
1
−
0
View file @
7b2fa303
...
...
@@ -14,6 +14,7 @@ struct _node_t *right;
node_t
*
bst_create
();
node_t
*
bst_create_node
(
int
val
);
void
bst_destroy
(
node_t
*
tree
);
bool
bst_is_empty
(
node_t
*
tree
);
void
bst_print
(
node_t
*
tree
,
int
prof
);
node_t
*
bst_insert
(
node_t
*
tree
,
int
val
);
node_t
*
bst_delete
(
node_t
*
tree
,
int
val
);
...
...
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