From 4843b0aea5e66abecbe11647753feff2af8005bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Mon, 7 Mar 2022 16:59:49 +0100 Subject: [PATCH] exercice tri --- .../C101_Algorithmes/Tri.class | Bin 1196 -> 1435 bytes .../C101_Algorithmes/Tri.java | 21 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bin/C10_Tri_et_complexite/C101_Algorithmes/Tri.class b/bin/C10_Tri_et_complexite/C101_Algorithmes/Tri.class index f09bb8395453c6c7d9d4466f59b8f2e8b8279ecf..b7ccf5b2a10971e0e71ec5dce9e1b3361b4c0353 100644 GIT binary patch literal 1435 zcma)5-EJFI5dO~ktk>DB8#|7jwzg?X3)rEt8-7AtJEm=DX^M+MsVrHMh&J|;Zm_-9 zdR>+KyaEppZgLAnN-IEl0N#NsUV;nM@SU|wRg#NZ+T)oy-^_gTbN+bo>k)uY@Pz?Q zU~z5v>efTw-ExAhw$~eUohNSKlxbbwy4BtBd^dR1bB1L?3`l{*uKn09ckTX8xv{-OECCJ-qUn*wsp>o`*on6{uJDlk)b`_7l6-nQdEw70vCz---X z+uf$^yGoxJqt!5si3k!F&LGB6!6SDlaHam{d@BM|1K;fjb$3XbdSP?D*qlNJXAR81 zR>{Wq!@%iTIEVA3?v02}*TX_xul$t?u@U%=-K!YL3CzE00nKiI=l00$b{yZtTUan~ z;q}lV!oo$oEnqyhyCbLZEyEYqi{lJoE5~svCbGD!3Vuf+PTm)rF}%lyFDPKq!Xn-m zh}wgJ)9(l@o#t^O$b@W|Yso?hWezUz#ta1J3a9c~#)k$z5J;WU6$>9J!g|`6t=D)ht7oTC~|1NsyVvPYvVwS*|s&?Z119|AQU0ZD3kVm!1>H#jFletp$ zDbl|o+sZyi{uwUKzI%wmA+8+a>YgTY`TgTR2{^>ZDqkd|m2YPObLkq0+Q(42H2Nsl}9)EKdbyObhf)XynN-X(D_lvJmZ(Eq`-c!9VOBBlM!`ZpY5 delta 717 zcmZ8fO-~b16g~INbY?moa41q}X-m-}{lJzgir7-os!@aKqJ*Sz zO`6&1ij^BTx@d`-{s1@n2lR)qpxzl>sEfH@@4R!)eVMm`_kR8B$)^E;W!&oOcfv}^ zZrPnOK}w}J336rUaYKg$e|Im}?ca-!VO&L!U_P<-tbEgIZRcw*pLZJ144lSQ?ZMU`!L=kgdQL+%ii~%1Kgo)JpUwj^{nBLTIhCm4&AtVjV;hgi0 zidqOM18HQOphzkU$f-E*l*Cje?-KcTS)!w30R;mWpb%7V(rhu4MGz0}a$)nwd8F2{ zww~U%b~mg?&4!94=e5YwsxuG~<(h#}oN|7OIa{yoyl8JVZrjZULEC8CIoB&@!H>ib z2aYTZg`>({o-=XwW%|%Qa3P>`bdPz607v6bZD52u%~j%w>U@{t`{rka>eEM<>LVVU z?cr<>^F3q_1Vv+q!yg}E_OR&EN*-;9DP0N^etr}U1r}Il0aqr((!dp5#1dx{VO+vx z7Fy_E{IL8E%7H|&?BH;C{J+gnM0nFUTS;IHi~Ps9HZ#A;v4-ow3PUD6$K-)- cuw#KFZ{&KHJnsRB6U?(`BEcpr%pq{|7lDLshyVZp 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); + } }