Skip to content

Commit e3143d9

Browse files
committed
Algorithm written in Java & modified
1 parent 656dd5c commit e3143d9

3 files changed

Lines changed: 51 additions & 5 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.class
2+
.idea
3+
untitled104.iml

tri-sélection/Algorithm.algo

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
// Correspond à la fonction du Tri Sélection
1+
// Correspond à la fonction Tri Sélection
22
FONCTION ENTIER TriSélection(Tableau T)
33
VARIABLE
4-
ENTIER: N <- 0
4+
ENTIER: i <- 0
5+
ENTIER: v <- 0
6+
ENTIER: pos <- 0
7+
ENTIER: min <- 0
58
POUR i variant de 0 à N-2
6-
Min <- i
9+
pos <- i
710
POUR v variant de i+1 à N-1
8-
SI T(v) < T(Min), alors Min <- v
11+
SI T(v) < T(pos), alors pos <- v
912
FINSI
1013
FINPOUR
11-
SI Min != i, ALORS échanger t[i] et t[min]
14+
Min <- T(pos)
15+
T(pos) <- T(i)
16+
T(i) <- Min
1217
FINSI
18+
RETOURNER Tableau(T)
1319
FINPOUR
1420
FINFONCTION

tri-sélection/src/Main.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import java.util.Arrays;
2+
public class Main {
3+
4+
5+
public static int[] selectedSort(int[] tableau) {
6+
int i;
7+
int min;
8+
int v;
9+
int pos;
10+
11+
12+
13+
for (i = 0; i < tableau.length - 1; i++) {
14+
pos = i;
15+
for (v = i + 1; v < tableau.length; v++) {
16+
if (tableau[v] < tableau[pos]) {
17+
pos = v;
18+
}
19+
}
20+
min = tableau[pos];
21+
tableau[pos] = tableau[i];
22+
tableau[i] = min;
23+
}
24+
return tableau;
25+
}
26+
public static void main(String[] args) {
27+
// write your code here
28+
// Clear console
29+
System.out.print("\033[H\033[2J");
30+
31+
// Tableau de test
32+
int[] tableau = { -1,6,29,9,7,8,5,-3,4,2,1,30,-30};
33+
34+
System.out.println("Tableau de test : "+Arrays.toString(selectedSort(tableau)));
35+
36+
}
37+
}

0 commit comments

Comments
 (0)