Skip to content

Commit 3964ccc

Browse files
committed
2 parents 927d385 + d425cab commit 3964ccc

9 files changed

Lines changed: 186 additions & 22 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.idea
33
untitled104.iml
44
.DS_Store
5+
.vscode

Algorithm-Stats.algo

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Tri à bulles optimisé
2+
FONCTION ENTIER Stats( min : INT, max : INT, step : INT, nbr : TABLEAU )
3+
// Définir les variables
4+
VARIABLE
5+
INT: i
6+
FLOAT: comparaisons
7+
FLOAT: echange
8+
FLOAT: affectations
9+
INT: tab[]
10+
// Début de l'algorithme
11+
DEBUT
12+
// On parcourt le tableau
13+
POUR i DE 1 A n FAIRE
14+
tab <- NombreAléatoire
15+
16+
FIN POUR
17+
18+
SI min < max ET i > nbr ALORS
19+
ECRIRE "Le nombre d'affectations pour " + min + " est de " + affectations / nbr;
20+
APPELER stat(min + step, max, step, nbr)
21+
SINON
22+
ECRIRE "Le nombre d'affectations pour " + min + " est de " + affectations / nbr;
23+
FIN SI
24+
FIN
25+
FIN FONCTION

Tri-de-selection/Algorithm-Iteratif.algo

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Correspond à la fonction Tri Sélection
22
FONCTION ENTIER TriSélection(Tableau T)
3+
DEBUT
34
VARIABLE
45
ENTIER: i <- 0
56
ENTIER: v <- 0
@@ -17,4 +18,5 @@ FONCTION ENTIER TriSélection(Tableau T)
1718
FINSI
1819
RETOURNER Tableau(T)
1920
FINPOUR
20-
FINFONCTION
21+
FIN
22+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Correspond à la fonction Tri Sélection Récursif
2+
ENTRÉE
3+
ENTIER: i
4+
VARIABLE
5+
ENTIER: v <- 0
6+
ENTIER: pos <- 0
7+
ENTIER: min <- 0
8+
pos <- i
9+
SI T(v) < T(pos) ALORS pos <- v
10+
FINSI
11+
Min <- T(pos)
12+
T(pos) <- T(i)
13+
T(i) <- Min
14+
SI i < N-2 && v < N-1 ALORS Appeler fonction TriSélectionRec()
15+
FINSI
16+
RETOURNER Tableau(T)
17+
FINFONCTION
18+

Tri-de-selection/src/Iteratif.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import java.util.Arrays;
2+
import java.util.Random;
3+
public class Iteratif {
4+
public static float echanges = 0;
5+
public static float comparaisons = 0;
6+
public static float affectations = 3*echanges;
7+
8+
9+
10+
public static int[] selectedSort(int[] tableau) {
11+
int i;
12+
int min;
13+
int v;
14+
int pos;
15+
16+
17+
18+
for (i = 0; i < tableau.length - 1; i++) {
19+
pos = i;
20+
21+
affectations+=1;
22+
comparaisons+=1;
23+
for (v = i + 1; v < tableau.length; v++) {
24+
if (tableau[v] < tableau[pos]) {
25+
pos = v;
26+
27+
comparaisons+=1;
28+
affectations+=1;
29+
}
30+
comparaisons+=1;
31+
}
32+
min = tableau[pos];
33+
tableau[pos] = tableau[i];
34+
tableau[i] = min;
35+
echanges += 1;
36+
affectations += 3;
37+
}
38+
return tableau;
39+
}
40+
public static void main(String[] args) {
41+
// write your code here
42+
// Clear console
43+
System.out.print("\033[H\033[2J");
44+
45+
// Tableau de test
46+
int[] tableau = {1,2,3,4,5,6,7,8,9,10};
47+
// int[] tableau = {10,9,8,7,6,5,4,3,2,1};
48+
// int[] tableau = {1,2,3,4,5,6,7,8,9,10};
49+
50+
System.out.println("Tableau de test : " + Arrays.toString(selectedSort(tableau)));
51+
System.out.println("Comparaisons : " + comparaisons);
52+
System.out.println("Echanges : " + echanges);
53+
System.out.println("Affectations : " + affectations );
54+
55+
stat(10,20,5,10);
56+
57+
}
58+
59+
60+
61+
public static void stat(int min,int max, int step, int nbr) {
62+
int i;
63+
comparaisons = 0;
64+
echanges = 0;
65+
affectations = 0;
66+
for ( i = 1 ; i <= nbr ; i++) {
67+
int Tab[] =new Random().ints(min).toArray();
68+
selectedSort(Tab);
69+
}
70+
if (min < max && i>nbr) {
71+
System.out.println("Le nombre d'affectations pour " + min + " est de " + affectations/nbr);
72+
stat((min+step),max,step,nbr);
73+
} else {
74+
System.out.println("Le nombre d'affectations pour " + min + " est de " + affectations/nbr);
75+
}
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import java.util.Arrays;
2-
public class Main {
2+
public class Recursif {
3+
public static int Opérations = 0;
4+
public static int Comparaisons = 0;
5+
public static int Affectations = 0;
36

47

5-
public static int[] selectedSort(int[] tableau) {
6-
int i;
8+
public static int[] selectedSort(int[] tableau, int i) {
79
int min;
810
int v;
911
int pos;
10-
11-
12-
13-
for (i = 0; i < tableau.length - 1; i++) {
12+
13+
if (i < tableau.length - 1) {
1414
pos = i;
1515
for (v = i + 1; v < tableau.length; v++) {
1616
if (tableau[v] < tableau[pos]) {
@@ -21,17 +21,20 @@ public static int[] selectedSort(int[] tableau) {
2121
tableau[pos] = tableau[i];
2222
tableau[i] = min;
2323
}
24+
if (i < tableau.length - 1) {
25+
selectedSort(tableau, i+1);
26+
}
2427
return tableau;
2528
}
2629
public static void main(String[] args) {
2730
// write your code here
2831
// Clear console
29-
System.out.print("\033\033");
32+
System.out.print("\033[H\033[2J");
3033

3134
// Tableau de test
3235
int[] tableau = { -1,6,29,9,7,8,5,-3,4,2,1,30,-30};
3336

34-
System.out.println("Tableau de test : " + Arrays.toString(selectedSort(tableau)));
37+
System.out.println("Tableau de test : " + Arrays.toString(selectedSort(tableau, 0)));
3538

3639
}
3740
}

Tri-insertion/src/Main.java

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,66 @@
1-
import java.util.Arrays;
1+
import java.util.Arrays;
2+
import java.util.Random;
23
public class Main {
4+
public static float affectation = 0;
5+
public static float echanges= 0;
6+
public static float comparaison = 0;
37
public static void main(String[] args) {
48
System.out.print("\033\033");
59

6-
int[] tableau = { 1, 3, 7, 2, 6, 4, 5, 8, 10, 9 };
10+
int[] tableau = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
711

812
System.out.println("Tableau de test : " + Arrays.toString(tri(tableau)));
13+
System.out.println("Nombre d'échanges : "+ echanges);
14+
System.out.println("Nombre de comparaisons :" + comparaison);
15+
System.out.println("Nombre d'affectations :" + affectation);
16+
stat(10,20,5,10);
917

1018
}
1119

1220
public static int[] tri(int[] tableau)
1321
{
14-
int taille = tableau.length;
22+
int taille = tableau.length;
23+
1524

1625
for (int i = 1; i < taille; i++)
1726
{
1827
int x = tableau[i];
19-
int j = i-1;
28+
int j = i-1;
29+
30+
affectation += 2;
31+
comparaison++;
32+
2033

2134
while(j >= 0 && tableau[j] > x)
2235
{
23-
tableau[j+1] = tableau[j];
36+
tableau[j+1] = tableau[j];
37+
echanges++;
38+
affectation+=1;
39+
comparaison+=2;
2440
j--;
25-
}
26-
tableau [j+1] = x;
41+
42+
43+
}
44+
tableau [j+1] = x;
45+
2746
}
28-
return tableau;
47+
return tableau;
2948
}
30-
49+
50+
public static void stat(int min,int max, int step, int nbr) {
51+
int i;
3152

32-
}
53+
for ( i = 1 ; i <= nbr ; i++) {
54+
int tableau[] =new Random().ints(min).toArray();
55+
tri(tableau);
56+
}
57+
if (min < max && i>nbr) {
58+
System.out.println("Le nombre d'affectations pour " + min + " est de " + affectation/nbr);
59+
stat((min+step),max,step,nbr);
60+
} else {
61+
System.out.println("Le nombre d'affectations pour " + min + " est de " + affectation/nbr);
62+
}
63+
64+
65+
}
66+
}

run.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
echo 'Tri à bulles Normal : '
2+
3+
java ./Tri-a-bulles-normal/src/Main.java
4+
15
echo 'Tri à bulles Optimisé : '
26

3-
java ./Tri-a-bulles-optimise/src/Main.java
7+
java ./Tri-a-bulles-optimise/src/Iteratif.java
48

59
echo '-- --- --'
610
echo 'Tri de Seleccion : '
711

8-
java ./Tri-de-selection/src/Main.java
12+
java ./Tri-de-selection/src/Iteratif.java
913

1014
echo '-- --- --'
1115
echo 'Tri d insertion : '

0 commit comments

Comments
 (0)