Skip to content

Commit cfa6af5

Browse files
committed
Merge branch 'Develop' into feature/tri_a_bulles_normal
2 parents e880faf + 4d23e37 commit cfa6af5

11 files changed

Lines changed: 228 additions & 19 deletions

File tree

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
1-
# Algorithm-Comparative-Sorting-Study
1+
2+
# Comparative sorting study in algorithms
3+
📒 - Exercise to learn to do comparative sorting with algorithms
4+
5+
## Contributing
6+
This repository is the result of a school exercise. It is therefore unnecessary to contribute to this project.
7+
8+
## License
9+
[MIT](https://choosealicense.com/licenses/mit/)
10+
11+
# Exercises
12+
13+
## Git
14+
- Décentraliser
15+
- Créer un dépôt local
16+
- Workflow Git
17+
- Ajout et versioning de fichiers
18+
- Obtenir des informations sur l’état de la copie de travail
19+
- Supprimer, déplacer et renommer des fichiers
20+
- Analyser l’historique des révisions
21+
- Ignorer des fichiers
22+
- Créer et gérer des branches
23+
- Merge : gérer les conflits
24+
- Push, pull, fetch
25+
- Comprendre rebase, reset
26+
- Débugger avec bisect
27+
- Gestions des dépôts avec GitHub
28+
29+
30+
## Algo : Etude comparative de tris
31+
32+
Le but de ce TP est de programmer, étudier et comparer les algorithmes élémentaires de tri
33+
34+
1. Faites les algorithmes des 4 tris :
35+
- Tri sélection
36+
- Tri insertion
37+
- Tri à bulles normal
38+
- Tri à bulles optimisé
39+
40+
2. Programmez :
41+
- Tri sélection
42+
- Tri insertion
43+
- Tri à bulles normal
44+
- Tri à bulles optimisé
45+
46+
3. Evaluez et comparez :
47+
48+
- Ajoutez un compteur des comparaisons et un des échanges/affectations dans le tableau (un
49+
échange vaut 3 affectations) ;
50+
51+
- Jeux d’essais avec meilleur et pire de cas : comptez les opérations nécessaires au mieux et au pire
52+
pour l’exécution des tris programmés ;
53+
54+
- Ecrire une méthode stat (int min, int max, int step, int nbr) qui fait varier la taille des tableaux tirés
55+
au sort de min jusqu’à max en avançant de step à chaque fois. Pour chaque taille, effectuez nbr
56+
générations aléatoires de tableaux et appelez la fonction de tri à tester. Indiquez sur la sortie
57+
standard la taille du tableau suivi du nombre moyen d’opérations effectués, avec une ligne pour
58+
chaque taille. Par exemple pour min = 10, max = 20, step = 5 et nbr = 10 on obtient quelque chose
59+
comme : 10 12.3, 15 27.4,20 32.4
60+
61+
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
// Tri à bulles optimisé
2-
FONCTION ENTIER TriBulle(tableau: t)
2+
FONCTION ENTIER TriBulle( tableau : INT )
33
// Définir les variables
44
VARIABLE
55
INT: n
66
BOOLEAN: echange
7+
INT: temp
78
// Début de l'algorithme
89
DEBUT
910
// Initialisation
10-
n <- TAILLE(tableau)
11-
echange <- VRAI
12-
temp
11+
n ◄- TAILLE(tableau)
12+
echange ◄- VRAI
1313

1414
// Tant qu'il y a echange
1515
TANT QUE echange EST VRAI FAIRE
1616
// Initialisation
17-
echange <- FAUX
17+
echange - FAUX
1818

1919
// On parcourt le tableau
2020
POUR i DE 1 A n FAIRE
2121
// On compare les éléments suivants
2222
SI tableau[i] > tableau[i+1] ALORS
2323
// On échange les valeurs
24-
temp <- tableau[i]
25-
tableau[i] <- tableau[i+1];
26-
tableau[i+1] <- temp;
27-
echange <- VRAI
24+
temp - tableau[i]
25+
tableau[i] - tableau[i+1];
26+
tableau[i+1] - temp;
27+
echange - VRAI
2828
FIN SI
2929
FIN POUR
3030
FIN TANT QUE
31-
RETOURNE tableau
31+
32+
RETOURNER tableau
33+
3234
FIN
33-
FIN FONCTION
34-
// al
35+
FIN FONCTION
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Tri à bulles optimisé
2+
FONCTION ENTIER TriBulle( tableau : INT )
3+
// Définir les variables
4+
VARIABLE
5+
INT: n
6+
INT: i
7+
INT: temp
8+
// Début de l'algorithme
9+
DEBUT
10+
// Initialisation
11+
n ◄- TAILLE(tableau)
12+
13+
// On parcourt le tableau
14+
POUR i DE 1 A n FAIRE
15+
// On compare les éléments suivants
16+
SI tableau[i] > tableau[i+1] ALORS
17+
// On échange les valeurs
18+
temp ◄- tableau[i]
19+
tableau[i] ◄- tableau[i+1]
20+
tableau[i+1] ◄- temp
21+
RETOURNER APPELER TriBulle(tableau)
22+
FIN SI
23+
FIN POUR
24+
25+
RETOURNER tableau
26+
FIN
27+
FIN FONCTION
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
// Import Arrays
22
import java.util.Arrays;
3+
import java.util.Random;
34

4-
public class Main {
5+
public class Iteratif {
56

67
public static void main(String[] args) {
78
// write your code here
89
// Clear console
910
System.out.print("\033\033");
11+
12+
Random rand = new Random();
1013

1114
// Tableau de test
12-
int[] tableau = { 1, 3, 7, 2, 6, 4, 5, 8, 10, 9 };
13-
14-
System.out.println("Tableau de test : "+Arrays.toString(triBulle(tableau)));
15+
int[] tableau = { rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100) };
1516

17+
System.out.println(Arrays.toString(triBulle(tableau)));
1618
}
1719

1820
public static int[] triBulle(int [] tableau) {
@@ -29,8 +31,7 @@ public static int[] triBulle(int [] tableau) {
2931
}
3032
}
3133
}
32-
33-
// Return le resultat
34+
3435
return tableau;
3536
}
3637
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Import Arrays
2+
import java.util.Arrays;
3+
import java.util.Random;
4+
5+
public class Recursif {
6+
7+
public static void main(String[] args) {
8+
// write your code here
9+
// Clear console
10+
System.out.print("\033\033");
11+
12+
Random rand = new Random();
13+
14+
// Tableau de test
15+
int[] tableau = { rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100), rand.nextInt(100) };
16+
17+
System.out.println(Arrays.toString(triBulle(tableau)));
18+
}
19+
20+
public static int[] triBulle(int [] tableau) {
21+
int n = tableau.length;
22+
23+
for (int i = 0; i < n - 1; i++) {
24+
if (tableau[i] > tableau[i + 1]) {
25+
int temp = tableau[i];
26+
tableau[i] = tableau[i + 1];
27+
tableau[i + 1] = temp;
28+
return triBulle(tableau);
29+
}
30+
}
31+
32+
return tableau;
33+
}
34+
}

Tri-insertion/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4+
<classpathentry kind="src" path="src"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

Tri-insertion/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

Tri-insertion/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Tri-insertion</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

Tri-insertion/algorithm.algo

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Correspond à la fonction Trouve disponible
2+
FONCTION Tri-insertion (Tableau T)
3+
4+
DEBUT
5+
taille = taille tableau
6+
Pour i = 1, i < taille , i + 1
7+
j = i- 1
8+
x = tableau[i]
9+
Pour i de 1 à taille(T) - 1
10+
TANTQUE j => 0 et tableau[j-1] > x
11+
tableau[j] <- tableau[j-1]
12+
j <- j-1
13+
tableau[j] <- x
14+
Retourne le tableau
15+
FIN
16+
FINFONCTION
17+

Tri-insertion/src/Main.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.util.Arrays;
2+
public class Main {
3+
public static void main(String[] args) {
4+
System.out.print("\033\033");
5+
6+
int[] tableau = { 1, 3, 7, 2, 6, 4, 5, 8, 10, 9 };
7+
8+
System.out.println("Tableau de test : " + Arrays.toString(tri(tableau)));
9+
10+
}
11+
12+
public static int[] tri(int[] tableau)
13+
{
14+
int taille = tableau.length;
15+
16+
for (int i = 1; i < taille; i++)
17+
{
18+
int x = tableau[i];
19+
int j = i-1;
20+
21+
while(j >= 0 && tableau[j] > x)
22+
{
23+
tableau[j+1] = tableau[j];
24+
j--;
25+
}
26+
tableau [j+1] = x;
27+
}
28+
return tableau;
29+
}
30+
31+
32+
}

0 commit comments

Comments
 (0)