Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cours
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
gaspard.legouic
cours
Commits
c58817fb
Verified
Commit
c58817fb
authored
2 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
mostly formating and added image
parent
30087801
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
slides/cours_16.md
+117
-10
117 additions, 10 deletions
slides/cours_16.md
slides/figs/heap_tree.svg
+498
-0
498 additions, 0 deletions
slides/figs/heap_tree.svg
with
615 additions
and
10 deletions
slides/cours_16.md
+
117
−
10
View file @
c58817fb
...
...
@@ -70,8 +70,8 @@ ajout(arbre, clé)
tree_t position(tree_t tree, key_t key) {
tree_t current = tree;
if (NULL != current) {
tree_t subtree =
key > current->key ? current->right :
current->left;
tree_t subtree =
key > current->key ? current->right :
current->left;
while (key != current->key && NULL != subtree) {
current = subtree;
subtree = key > current->key ? current->right :
...
...
@@ -95,7 +95,7 @@ tree_t position(tree_t tree, key_t key) {
```
C
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;
if (NULL == *tree) {
*tree = new_node;
...
...
@@ -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)
\f
ootnotesize
```
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)
\f
ootnotesize
```
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
...
...
@@ -132,7 +237,7 @@ tree_t add_key(tree_t *tree, key_t key) {
## Une feuille (le 19 p.ex.).
```
{.mermaid format=pdf width=
40
0 loc=figs/}
```
{.mermaid format=pdf width=
15
0 loc=figs/}
flowchart TB;
10-->20;
10-->5
...
...
@@ -259,6 +364,8 @@ arbre parent(arbre, sous_arbre)
# Le pseudo-code de la suppression
\f
ootnotesize
## Pour un seul enfant (5min -> matrix)
. . .
...
...
@@ -274,7 +381,7 @@ arbre suppression(arbre, clé)
sinon
gauche(parent) = droite(sous_arbre)
sinon
si droite(parent) == sous_arbre
si droite(parent) == sous_arbre
ou est_
droite(parent) = gauche(sous_arbre)
sinon
gauche(parent) = gauche(sous_arbre)
...
...
@@ -983,7 +1090,7 @@ graph TD;
*
Échanger la racine,
`7`
(
`max`
de l'arbre) avec
`2`
.
*
Traiter la racine.
```
{.mermaid format=pdf width=
40
0 loc=figs/}
```
{.mermaid format=pdf width=
15
0 loc=figs/}
graph TD;
id0((2))-->id1((6));
id0-->id2((5));
...
...
@@ -1000,7 +1107,7 @@ graph TD;
*
`2 <=> max(2, 6, 5)`
.
*
`2 <=> max(2, 1, 4)`
.
```
{.mermaid format=pdf width=
40
0 loc=figs/}
```
{.mermaid format=pdf width=
15
0 loc=figs/}
graph TD;
id0((6))-->id1((4));
id0-->id2((5));
...
...
@@ -1031,7 +1138,7 @@ graph TD;
*
Échanger la racine,
`6`
(
`max`
de l'arbre) avec
`2`
.
*
Traiter la racine.
```
{.mermaid format=pdf width=
40
0 loc=figs/}
```
{.mermaid format=pdf width=
15
0 loc=figs/}
graph TD;
id0((2))-->id1((4));
id0-->id2((5));
...
...
This diff is collapsed.
Click to expand it.
slides/figs/heap_tree.svg
0 → 100644
+
498
−
0
View file @
c58817fb
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