Skip to content
Snippets Groups Projects
Commit a7590807 authored by Pierre Kunzli's avatar Pierre Kunzli
Browse files

re re correction code recherche parent et code recherche

parent abd92514
No related branches found
No related tags found
4 merge requests!6Pk,!5Pk,!4correction recherche parent et ajout sauts slides,!3Re re correction recherche
Pipeline #15720 passed
...@@ -790,7 +790,7 @@ typedef struct _node { ...@@ -790,7 +790,7 @@ typedef struct _node {
typedef node* tree_t; typedef node* tree_t;
tree_t search(key_t key, tree_t tree) { tree_t search(key_t key, tree_t tree) {
tree_t current = tree; tree_t current = tree;
while (NULL != current && !success) { while (NULL != current) {
if (current->key > X) { if (current->key > X) {
current = current->gauche; current = current->gauche;
} else if (current->key < X){ } else if (current->key < X){
...@@ -877,12 +877,17 @@ int arbre_size(tree_t tree) { ...@@ -877,12 +877,17 @@ int arbre_size(tree_t tree) {
``` ```
arbre position(arbre, clé) arbre position(arbre, clé)
si est_non_vide(arbre) si est_non_vide(arbre)
si clé < clé(arbre)
suivant = gauche(arbre)
sinon
suivant = droite(arbre)
tant que clé(arbre) != clé && est_non_vide(suivant) tant que clé(arbre) != clé && est_non_vide(suivant)
arbre = suivant
si clé < clé(arbre) si clé < clé(arbre)
suivant = gauche(arbre) suivant = gauche(arbre)
sinon sinon
suivant = droite(arbre) suivant = droite(arbre)
arbre = suivant
returne arbre returne arbre
``` ```
...@@ -917,10 +922,12 @@ ajout(arbre, clé) ...@@ -917,10 +922,12 @@ ajout(arbre, clé)
tree_t position(tree_t tree, key_t key) { tree_t position(tree_t tree, key_t key) {
tree_t current = tree; tree_t current = tree;
if (NULL != current) { if (NULL != current) {
subtree = key > current->key ? current->right :
current->left;
while (key != current->key && NULL != subtree) { while (key != current->key && NULL != subtree) {
current = subtree;
subtree = key > current->key ? current->right : subtree = key > current->key ? current->right :
current->left; current->left;
current = subtree;
} }
} }
return current; return current;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment