From 454ffa9c34bef51a118486c93cf09cdd72fbd828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Mon, 7 Mar 2022 17:28:31 +0100 Subject: [PATCH] Selection exercice --- .../C103_Algorithme_de_tri/App.class | Bin 652 -> 0 bytes .../C103_Algorithme_de_tri/Selection.class | Bin 0 -> 1723 bytes .../C103_Algorithme_de_tri/App.java | 7 --- .../C103_Algorithme_de_tri/Selection.java | 47 ++++++++++++++++++ 4 files changed, 47 insertions(+), 7 deletions(-) delete mode 100644 bin/C10_Tri_et_complexite/C103_Algorithme_de_tri/App.class create mode 100644 bin/C10_Tri_et_complexite/C103_Algorithme_de_tri/Selection.class delete mode 100644 src/C10_Tri_et_complexite/C103_Algorithme_de_tri/App.java create mode 100644 src/C10_Tri_et_complexite/C103_Algorithme_de_tri/Selection.java 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 628ab4370fb947366b2b1649d8a1ffb736d437f1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 652 zcmb7B%T60X5Ueo^YcJ*z8xs-|9(hPk6tR#TI5>)g5K#^miDU!^4y*BcWCqRdtkz=$ zp9KeyIOGHJQBi755(|k7m+tAVnd++PU%zjE0@%h|A0>g!-L1{&AlH#{QEZdUsB`U9 z$nK|T$MkKk-ASUNo{C(q!<{Vi;R(#2$}<@nnfAl)-BT4ifvL|r)$WVHMDyLDfVXRV zD!>FPRZL<^V6LrGwLeU{DnF22qXcSg8%uL2b6wPbo1Qz-1A&k2$LeZvW+HVeu-H6q zkM(t^JMFg$O~KxItTLx`M=DsrqL0QskDZHwQ%Mz1u|$7%NV|=@5!!}7 z$nQ8s$)r`rbAg#}${71$?a1b)w;tdHR(!ntH}3w6Dps*3;AaJiq4-AgVeOvG`}~*s z1J-D)V~2UHzUtyz%Use%;SB4bTJ9Ps@x(1K`m91`!94l?2Ib2U955Cz_+Xl`dUt_& xhE)Z#m?OzN&mNH{Bbx0IEzv8~YtOE+Jf;c=ksoD}j_E2?^oo6f*Ni2+`2%N6lR*Fg 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 0000000000000000000000000000000000000000..180e432fd83d126a762850b3bb0960d5b2f28b85 GIT binary patch literal 1723 zcmbVMO;;Ob6n@@hl7Z=jLSPUGQChH)5R%f5fP|tg7R4rn5=1ec6NhA^gZVmPQqeX4 z!8P5mRTrU0Jp2IvgIkX)*RH_lo$z4~tXyQ~zW3huxzBy>o&0|C>oI_7e5Jx8kX)F$ zTUcw@1R-t4SoQ9pqS!Ju}*tMz(MWB1zd}$`i zW_2r(-P~qCK&hB^RiJ-7pS}#{c(uBfimVH0Pj`z}T_WtL=oIL^%({pWWuaEGGzjQA z0_YO(&)HSmnP+5tNy6Mr+f{41S=qE2YvyLz5(uViMYFtaHf(u5b1G(IYllUyA)~>I zK8bD!c*i5_vf5iZ1~4d~R;};S_72JUP z$NQKiom!J%M*FH=ORPv`IBUzSq*TmN&&%PqSKvw0E|;u^hIxFb;)6G#-6hfS7*ELc zrCDxT*>4C>u2)w{Lkb_s={=PhSL2cO4t&hkMr7iWj!*H7OJvsTR<$HBdEJdGAZKJ# z5+b8x8Cii2r`GO7pl|$IUeA$Jv3kDPZ>pkWO%nFGE7Sq*vCuR;#}_&_WI%NTWlmem z)tZf>wP?%L?z;Hu;!;rD;yQZy2?Gi`;e#I@sP2gbq0ySANATTw1kqhO#EqYM@Zct& z8sGBSfg9+irMDB&gCI|kpBp^{5%&l$VZV+ZqBk09p+6IQjUn&+0TyE6cv1-`ec`14 z0E02ZA2*a&2uLHT82+Sh&o2yr?0En5PnqhEg=2;vXZO4!96MG@`=>_|P;&FS z+!o0~GEm4tqo<1ud+8e>w-Bvc=tC3+*SQ}Lc%H`~7BIx=hOoliJi;j8ZMUygc1Z3# zy~DS(MqJ@Etm8IDsX{lNVT?X6@n`TZErmD_afgDo zAyh=E@(BV$h@j^m-iG`GY3qkq#PiV;3H_#Jjxe!th{vw;Abs-emTj0mtd4+Cs;O$DNOP|Bkq##cQB?@{5U3$W$ X*9*@n7t=?AZGFKp2z*KA9_0T8>gZ58 literal 0 HcmV?d00001 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"); + } +}