From c68ec4e11bbbb8b470e55f0d66d26d3d1681b7b8 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Fri, 6 Nov 2020 23:03:28 +0700 Subject: [PATCH] Make reverse a lot simpler --- Assignment10/bin/RecursiveExercise.class | Bin 3744 -> 3537 bytes Assignment10/src/RecursiveExercise.java | 11 +---------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/Assignment10/bin/RecursiveExercise.class b/Assignment10/bin/RecursiveExercise.class index f1c3ad2e42d7ed26633c63c34184869ca23cc9ef..cbdeec5ba5741e0b1560d3cad4de75ed074dbfa7 100644 GIT binary patch literal 3537 zcmb7GTTolq6d6HYY_NqNksUYafuR_i)FO$4UF;Hr6+?^zq;;;O3tU@BR1b_} zCv_4xj@`VIzTA9dGWp6diIWe^v>7*FP1~PNr~T|t+pmtN(~rz_`jvK_dxby<+6G2f z`<}D++G{_~*7@z1KfePYjyJuK0{0A?sZzdR&6)l4WVK1u5e^jKs%aCn*q4s*WrdoVAG(LHBXjil4kyKBbhM;ng(+zBQt8` zE%jbr)QZzqL16P>jpJVWFlJ}XY+Aq0)!IfZ~JohSoU)K?_nOlVc!h3AD<7(%CjxOw{w|RaH=BZFh z+VLuKcFJtExQ++#4Kg&k)Pn}@!n8GMhcGd)oQ6kqJOmb0E1EO2{F*T=dTR+!tYS4% z%v;&1-pHsQ{W$K$v8vt}xmcjBj&Fg{yK*HuXm*UPT<2r7EYjXIW_o=%A+WvAu5M^w zsDFNzJ!Pijp|1AO{`OFJM*u@ecyV&MzSZ_R9>XbyIIAEtB-tEZkE0JGjP$r!jE5B7 zX&s}=%x#;gsy?As#<-&DJnF-Q0DSniz}}6iwTBM0hYq%fdOCbKE3jwSscBUd+@?~u z9ZMJWSeX`8yDFt(zGQZIkrLRtQgtW4M@m*EZRP_=!c@oUl#-@Ymre`p2#>GslPU`) z_8dEb=}UtB-hdf_ee30>CS7Hh?6)LxI%e@*c2hCups(#sXO+%)a<|q5HfdxECZjI# zWG(k&ZR9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!h5;FDvYiKxD#$z)q?wsK zkC{mFM=1$51397wC`LJ=jxuEdUWue$5NdnKQOszuVPnzqK7wN99u9ML#p zL_UQ#IuqqJG837@y67CjeKa;5*xWjYM`q~baWZUi)&;mK$ZR40RWO5&T4t$d4wX6L z#>As&L$i)=DY^!^D-VgU>U;O%%^JVRtUvRzI5!!PK&ZI$9eDb|Vh* zzCdAjv5*qfNWS4exi(D{ynCkWqb^kr z8S!cQxZ7AqErFZiXZRq)SCRa++&EQrof`}LIH&#@*zdq8)*tk91>Y@YD6SS!w5YAp zrX!vhRTO_0HN~xQWp!}c*+V*b7T~z5Y9l|7k)3ujvx6M%q;7T*#O_6~TJS`Xr4}5X zhvkLGw^8BZ+pG-Nb=ItQsL7Skrn`>FJ+b`_O6k-H1U=Dz|Rl?hN$)>;@+?p_LjmV zR|ykXns~^^2>w7K?hE_KjDx^hWvSy5-{V(^MqQs@z#gg@x`*?%{#lIIOw1xTi%HH^ z`&GR7o`7<`wA?wc)Oo%%A1fi2;A$X4t4&mhxIQ0+6{#qd;b1s4hl4KQ%gZq=0~`*8 zEB=3H{fjsU!Q2>xd9VKx ziruyt>V?%piG@HfuI4lU8WY=ibl{xiF4Ul#9r;Oip&s_Br_hQcYzjv?o8TwmF`UNJ z7)3v_7(kw%e3v=;CQjlmhVUUy;Uf&=CwLaK^n8Fb_!Uh21xY+a3ZKCeRs2*lV2i!{ zEbGU4aU5xJ78#M{ht~y6h}+1C_mLMr=7-fMm=eFi1@U`+D*c^bLjS~N@j0%@dORl| z#q%oScSvVfcN3SO4i@QS>FSLH3dChy{P`5|t}kMM^4 zDQ?SqcuW2gZ_7{dj{F_&$Uov;`6s+5|BCnJL;OH~h9Am*;YVy{dHA3gN&3k0L5tXd_W4uLc4IALw3K8D< E4}>H8&j0`b diff --git a/Assignment10/src/RecursiveExercise.java b/Assignment10/src/RecursiveExercise.java index af58b2c..1b5e706 100644 --- a/Assignment10/src/RecursiveExercise.java +++ b/Assignment10/src/RecursiveExercise.java @@ -20,18 +20,9 @@ public class RecursiveExercise { return null; if (ht.length == 1) return ht.clone(); - return append(new int[] { ht[ht.length - 1] }, append( - reverse(MyArrayUtil.tail(removeLast(ht.clone(), new int[ht.length - 1], 0))), new int[] { ht[0] })); + return append(reverse(MyArrayUtil.tail(ht)),new int[] {MyArrayUtil.head(ht)}); } - // Remove the last element - - public static int[] removeLast(int[] ia1, int[] ia2, int i) { - ia2[i] = ia1[i]; - if (i == ia2.length - 1) - return ia2; - return removeLast(ia1, ia2, i + 1); - } public static boolean isIn(int x, int[] a) throws Exception { // fill your code here