Commit use append

This commit is contained in:
Siwat Sirichai 2020-11-03 14:57:47 +07:00
parent 48d8a7bf72
commit 5137559993
2 changed files with 1 additions and 4 deletions

View File

@ -61,12 +61,9 @@ public class RecursiveExercise {
if(ht==null)return null; if(ht==null)return null;
if(n==0)return ht; if(n==0)return ht;
int temp = ht[0]; int temp = ht[0];
ht = insertLast(temp,MyArrayUtil.tail(ht)); ht = reverse(MyArrayUtil.addAsFirst(temp, reverse(MyArrayUtil.tail(ht))));
return shift(ht,n-1); return shift(ht,n-1);
} }
public static int[] insertLast(int val,int[] ia) throws Exception{
return reverse(MyArrayUtil.addAsFirst(val, reverse(ia)));
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// test append, when appending empty array with {1,2,3} // test append, when appending empty array with {1,2,3}
int[] a = null; int[] a = null;