Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
algoprog-etu-22-23
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
aliya.myaz
algoprog-etu-22-23
Commits
de4da5a2
Commit
de4da5a2
authored
2 years ago
by
Pierre Kunzli
Browse files
Options
Downloads
Patches
Plain Diff
ajout demo arbre
parent
3a126a03
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Programmation/Code/Arbre/arbre.c
+91
-0
91 additions, 0 deletions
Programmation/Code/Arbre/arbre.c
with
91 additions
and
0 deletions
Programmation/Code/Arbre/arbre.c
0 → 100644
+
91
−
0
View file @
de4da5a2
#include
<stdio.h>
#include
<stdlib.h>
typedef
struct
_node
{
int
cle
;
struct
_node
*
left
,
*
right
;
}
node
;
typedef
node
*
tree
;
void
parcours_grd
(
tree
arbre
,
int
n
){
if
(
arbre
!=
NULL
){
parcours_grd
(
arbre
->
left
,
n
+
1
);
for
(
int
i
=
0
;
i
<
n
;
i
++
){
printf
(
" "
);
}
printf
(
"%d
\n
"
,
arbre
->
cle
);
parcours_grd
(
arbre
->
right
,
n
+
1
);
}
}
tree
recherche
(
tree
arbre
,
int
cle
){
while
(
arbre
!=
NULL
){
if
(
cle
>
arbre
->
cle
){
arbre
=
arbre
->
right
;
}
else
if
(
cle
<
arbre
->
cle
){
arbre
=
arbre
->
left
;
}
else
{
return
arbre
;
}
}
return
arbre
;
}
int
taille
(
tree
arbre
){
if
(
arbre
==
NULL
){
return
0
;
}
return
1
+
taille
(
arbre
->
left
)
+
taille
(
arbre
->
right
);
}
tree
creer_noeud
(
int
cle
){
tree
res
=
malloc
(
sizeof
(
node
));
res
->
left
=
NULL
;
res
->
right
=
NULL
;
res
->
cle
=
cle
;
return
res
;
}
tree
trouver_parent
(
tree
arbre
,
int
cle
){
tree
courant
=
arbre
;
tree
suivant
=
arbre
;
while
(
suivant
!=
NULL
&&
courant
->
cle
!=
cle
){
courant
=
suivant
;
if
(
cle
<
suivant
->
cle
){
suivant
=
suivant
->
left
;
}
else
if
(
cle
>
suivant
->
cle
){
suivant
=
suivant
->
right
;
}
}
return
courant
;
}
tree
inserer
(
tree
arbre
,
int
cle
){
tree
parent
=
trouver_parent
(
arbre
,
cle
);
if
(
parent
==
NULL
){
return
creer_noeud
(
cle
);
}
if
(
cle
<
parent
->
cle
){
parent
->
left
=
creer_noeud
(
cle
);
}
else
if
(
cle
>
parent
->
cle
){
parent
->
right
=
creer_noeud
(
cle
);
}
return
arbre
;
}
int
main
(){
tree
arbre
=
NULL
;
arbre
=
inserer
(
arbre
,
10
);
arbre
=
inserer
(
arbre
,
7
);
arbre
=
inserer
(
arbre
,
25
);
arbre
=
inserer
(
arbre
,
12
);
arbre
=
inserer
(
arbre
,
38
);
parcours_grd
(
arbre
,
0
);
printf
(
"Taille : %d
\n
"
,
taille
(
arbre
));
}
\ No newline at end of file
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