diff --git a/bin/C10_Tri_et_complexite/C103_Algorithme_de_tri/App.class b/bin/C10_Tri_et_complexite/C103_Algorithme_de_tri/App.class deleted file mode 100644 index 628ab43..0000000 Binary files a/bin/C10_Tri_et_complexite/C103_Algorithme_de_tri/App.class and /dev/null differ diff --git a/bin/C10_Tri_et_complexite/C103_Algorithme_de_tri/Selection.class b/bin/C10_Tri_et_complexite/C103_Algorithme_de_tri/Selection.class new file mode 100644 index 0000000..180e432 Binary files /dev/null and b/bin/C10_Tri_et_complexite/C103_Algorithme_de_tri/Selection.class differ diff --git a/src/C10_Tri_et_complexite/C103_Algorithme_de_tri/App.java b/src/C10_Tri_et_complexite/C103_Algorithme_de_tri/App.java deleted file mode 100644 index 0c83398..0000000 --- a/src/C10_Tri_et_complexite/C103_Algorithme_de_tri/App.java +++ /dev/null @@ -1,7 +0,0 @@ -package C10_Tri_et_complexite.C103_Algorithme_de_tri; - -public class App { - public static void main(String[] args) throws Exception { - System.out.println("Hello, World!"); - } -} diff --git a/src/C10_Tri_et_complexite/C103_Algorithme_de_tri/Selection.java b/src/C10_Tri_et_complexite/C103_Algorithme_de_tri/Selection.java new file mode 100644 index 0000000..4799e56 --- /dev/null +++ b/src/C10_Tri_et_complexite/C103_Algorithme_de_tri/Selection.java @@ -0,0 +1,47 @@ +package C10_Tri_et_complexite.C103_Algorithme_de_tri; + +import java.util.Random; + +// Tri d'un tableau; + +public class Selection { + + public static void main(String[] args) throws Exception { + new Selection(100); + } + + Selection(int n){ + int[] a = newList(n); + printList(a); + 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); + } + + int[] newList(int size){ + int[] a = new int[size]; + Random r = new Random(); + for (int i = 0; i < a.length; i++) { + a[i] = r.nextInt(1000); + } + return a; + } + + static void printList(int[] a){ + for (int i : a) { + System.out.print(i + " "); + } + System.out.println("\n"); + } +}