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
algorithmique
cours
Commits
f622ba10
Verified
Commit
f622ba10
authored
3 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
added C code
parent
a675ca30
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#15819
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
slides/cours_16.md
+59
-4
59 additions, 4 deletions
slides/cours_16.md
with
59 additions
and
4 deletions
slides/cours_16.md
+
59
−
4
View file @
f622ba10
...
@@ -17,7 +17,7 @@ patat:
...
@@ -17,7 +17,7 @@ patat:
# Un joli site
# Un joli site
## V
I
sualisation d'algorithmes
## V
i
sualisation d'algorithmes
*
<https://visualgo.net/>
*
<https://visualgo.net/>
*
Allons nous rafraîchir la mémoire sur l'insertion / recherche dans un arbre
*
Allons nous rafraîchir la mémoire sur l'insertion / recherche dans un arbre
...
@@ -1193,7 +1193,7 @@ graph TD;
...
@@ -1193,7 +1193,7 @@ graph TD;
*
Postez le résultat sur matrix.
*
Postez le résultat sur matrix.
# L'algorithme du tri par tas (1/
3
)
# L'algorithme du tri par tas (1/
4
)
## Deux étapes
## Deux étapes
...
@@ -1221,7 +1221,7 @@ promotion(tab, i)
...
@@ -1221,7 +1221,7 @@ promotion(tab, i)
promotion(tab, ind_max)
promotion(tab, ind_max)
```
```
# L'algorithme du tri par tas (2/
3
)
# L'algorithme du tri par tas (2/
4
)
*
Fonctions utilitaires
*
Fonctions utilitaires
...
@@ -1240,10 +1240,65 @@ int droite(i)
...
@@ -1240,10 +1240,65 @@ int droite(i)
```
```
# L'algorithme du tri par tas (2/2)
# L'algorithme du tri par tas (3/4)
\f
ootnote size
## Implémenter en C l'algorithme du tri par tas (matrix, 20min)
## Implémenter en C l'algorithme du tri par tas (matrix, 20min)
. . .
. . .
```
C
void heapsort(int size, int tab[size]) {
heapify(size, tab);
swap(tab, tab + size - 1);
for (int s = size - 1; s > 1; s--) {
sift_up(s, tab, 0);
swap(tab, tab + s - 1);
}
}
void heapify(int size, int tab[size]) {
for (int i = size / 2 - 1; i >= 0; i--) {
sift_up(size, tab, i);
}
}
void sift_up(int size, int tab[size], int i) {
int ind_max = ind_max3(size, tab, i, left(i), right(i));
if (i != ind_max) {
swap(tab + i, tab + ind_max);
sift_up(size, tab, ind_max);
}
}
```
# L'algorithme du tri par tas (3/4)
\f
ootnotesize
## Fonctions utilitaires
. . .
```
C
int ind_max3(int size, int tab[size], int i, int l, int r) {
int ind_max = i;
if (l < size && tab[ind_max] < tab[l]) {
ind_max = l;
}
if (r < size && tab[ind_max] < tab[r]) {
ind_max = r;
}
return ind_max;
}
void swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
int left(int i) {
return 2 * i + 1;
}
int right(int i) {
return 2 * i + 2;
}
```
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