diff --git a/bin/C10_Tri_et_complexite/C101_Algorithmes/Tri.class b/bin/C10_Tri_et_complexite/C101_Algorithmes/Tri.class index f09bb83..b7ccf5b 100644 Binary files a/bin/C10_Tri_et_complexite/C101_Algorithmes/Tri.class and b/bin/C10_Tri_et_complexite/C101_Algorithmes/Tri.class differ diff --git a/src/C10_Tri_et_complexite/C101_Algorithmes/Tri.java b/src/C10_Tri_et_complexite/C101_Algorithmes/Tri.java index 7a2ada1..789099e 100644 --- a/src/C10_Tri_et_complexite/C101_Algorithmes/Tri.java +++ b/src/C10_Tri_et_complexite/C101_Algorithmes/Tri.java @@ -4,18 +4,31 @@ package C10_Tri_et_complexite.C101_Algorithmes; public class Tri { + static int [] a = {4, 7, 1, 3, 6}; + static void printList(int[] a){ for (int i : a) { System.out.print(i + " "); } System.out.println(); } + public static void main(String[] args) throws Exception { - int [] a = {4, 7, 1, 3, 6}; printList(a); - int min = 0; - for (int i = min+1; i < a.length; i++) { - + for (int i = 0; i < a.length-1; i++) { + int min = a[i]; + int iMin = i; + for (int j = i; j < a.length; j++) { + if(a[j] < min){ + min = a[j]; + iMin = j; + } + } + int tmp = a[i]; + a[i] = a[iMin]; + a[iMin] = tmp; } + printList(a); + } }