Skip to content
Snippets Groups Projects
Verified Commit c58817fb authored by orestis.malaspin's avatar orestis.malaspin
Browse files

mostly formating and added image

parent 30087801
No related branches found
No related tags found
No related merge requests found
...@@ -70,8 +70,8 @@ ajout(arbre, clé) ...@@ -70,8 +70,8 @@ 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) {
tree_t subtree = key > current->key ? current->right : tree_t subtree =
current->left; key > current->key ? current->right : current->left;
while (key != current->key && NULL != subtree) { while (key != current->key && NULL != subtree) {
current = subtree; current = subtree;
subtree = key > current->key ? current->right : subtree = key > current->key ? current->right :
...@@ -95,7 +95,7 @@ tree_t position(tree_t tree, key_t key) { ...@@ -95,7 +95,7 @@ tree_t position(tree_t tree, key_t key) {
```C ```C
tree_t add_key(tree_t *tree, key_t key) { tree_t add_key(tree_t *tree, key_t key) {
node_t *new_node = calloc(1, sizeof(*new_node)); // nouveauté! node_t *new_node = calloc(1, sizeof(*new_node));
new_node->key = key; new_node->key = key;
if (NULL == *tree) { if (NULL == *tree) {
*tree = new_node; *tree = new_node;
...@@ -115,10 +115,115 @@ tree_t add_key(tree_t *tree, key_t key) { ...@@ -115,10 +115,115 @@ tree_t add_key(tree_t *tree, key_t key) {
} }
``` ```
# La suppression de clé # La version PK (1/N)
```C
typedef struct _node {
int info;
struct _node *left, *right;
} node;
typedef node *tree;
void parcours_infixe(tree arbre, int n){
if(arbre!=NULL){
parcours_infixe(arbre->left, n+1);
for(int i=0; i<n; i++){
printf(" ");
}
printf("%d\n", arbre->info);
parcours_infixe(arbre->right, n+1);
}
}
```
# La version PK (2/N)
```C
tree recherche(int cle, tree arbre){
while(arbre != NULL){
if(arbre->info == cle) return arbre;
if(arbre->info > cle){
arbre = arbre->left;
}else if(arbre->info < cle){
arbre = arbre->right;
}
}
return NULL;
}
```
# La version PK (3/N)
\footnotesize
```C
node* parent_insertion(int donnee, tree arbre){
if(arbre != NULL){
node* suivant = NULL;
if(arbre->info > donnee){
suivant = arbre->left;
} else {
suivant = arbre->right;
}
while(suivant != NULL && arbre->info != donnee){
arbre = suivant;
if(arbre->info > donnee){
suivant = arbre->left;
} else {
suivant = arbre->right;
}
}
}
return arbre;
}
```
# La version PK (4/N)
\footnotesize
```C
node* nouveau_noeud(int donnee){
node* new_node = malloc(sizeof(node));
new_node->info = donnee;
new_node->left = NULL;
new_node->right = NULL;
return new_node;
}
tree insertion(int donnee, tree arbre){
if(arbre == NULL){
arbre = nouveau_noeud(donnee);
} else {
node* parent = parent_insertion(donnee, arbre);
if(donnee > parent->info){
parent->right = nouveau_noeud(donnee);
} else if(donnee < parent->info) {
parent->left = nouveau_noeud(donnee);
}
}
return arbre;
}
```
# La version PK (5/N)
```C
int main(){
tree arbre = NULL;
arbre = insertion(2, arbre);
arbre = insertion(1, arbre);
arbre = insertion(8, arbre);
arbre = insertion(10, arbre);
arbre = insertion(5, arbre);
parcours_infixe(arbre, 0);
}s
```
# La suppression de clé
. . .
::: columns ::: columns
...@@ -132,7 +237,7 @@ tree_t add_key(tree_t *tree, key_t key) { ...@@ -132,7 +237,7 @@ tree_t add_key(tree_t *tree, key_t key) {
## Une feuille (le 19 p.ex.). ## Une feuille (le 19 p.ex.).
```{.mermaid format=pdf width=400 loc=figs/} ```{.mermaid format=pdf width=150 loc=figs/}
flowchart TB; flowchart TB;
10-->20; 10-->20;
10-->5 10-->5
...@@ -259,6 +364,8 @@ arbre parent(arbre, sous_arbre) ...@@ -259,6 +364,8 @@ arbre parent(arbre, sous_arbre)
# Le pseudo-code de la suppression # Le pseudo-code de la suppression
\footnotesize
## Pour un seul enfant (5min -> matrix) ## Pour un seul enfant (5min -> matrix)
. . . . . .
...@@ -274,7 +381,7 @@ arbre suppression(arbre, clé) ...@@ -274,7 +381,7 @@ arbre suppression(arbre, clé)
sinon sinon
gauche(parent) = droite(sous_arbre) gauche(parent) = droite(sous_arbre)
sinon sinon
si droite(parent) == sous_arbre si droite(parent) == sous_arbreou est_
droite(parent) = gauche(sous_arbre) droite(parent) = gauche(sous_arbre)
sinon sinon
gauche(parent) = gauche(sous_arbre) gauche(parent) = gauche(sous_arbre)
...@@ -983,7 +1090,7 @@ graph TD; ...@@ -983,7 +1090,7 @@ graph TD;
* Échanger la racine, `7` (`max` de l'arbre) avec `2`. * Échanger la racine, `7` (`max` de l'arbre) avec `2`.
* Traiter la racine. * Traiter la racine.
```{.mermaid format=pdf width=400 loc=figs/} ```{.mermaid format=pdf width=150 loc=figs/}
graph TD; graph TD;
id0((2))-->id1((6)); id0((2))-->id1((6));
id0-->id2((5)); id0-->id2((5));
...@@ -1000,7 +1107,7 @@ graph TD; ...@@ -1000,7 +1107,7 @@ graph TD;
* `2 <=> max(2, 6, 5)`. * `2 <=> max(2, 6, 5)`.
* `2 <=> max(2, 1, 4)`. * `2 <=> max(2, 1, 4)`.
```{.mermaid format=pdf width=400 loc=figs/} ```{.mermaid format=pdf width=150 loc=figs/}
graph TD; graph TD;
id0((6))-->id1((4)); id0((6))-->id1((4));
id0-->id2((5)); id0-->id2((5));
...@@ -1031,7 +1138,7 @@ graph TD; ...@@ -1031,7 +1138,7 @@ graph TD;
* Échanger la racine, `6` (`max` de l'arbre) avec `2`. * Échanger la racine, `6` (`max` de l'arbre) avec `2`.
* Traiter la racine. * Traiter la racine.
```{.mermaid format=pdf width=400 loc=figs/} ```{.mermaid format=pdf width=150 loc=figs/}
graph TD; graph TD;
id0((2))-->id1((4)); id0((2))-->id1((4));
id0-->id2((5)); id0-->id2((5));
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment