|
@@ -1,6 +1,4 @@
|
1
|
|
-import java.util.ArrayList;
|
2
|
|
-import java.util.Arrays;
|
3
|
|
-import java.util.TreeMap;
|
|
1
|
+import java.util.*;
|
4
|
2
|
|
5
|
3
|
public class Arraz {
|
6
|
4
|
|
|
@@ -73,24 +71,20 @@ public class Arraz {
|
73
|
71
|
}
|
74
|
72
|
|
75
|
73
|
|
76
|
|
-// public Integer[] copyArrayByIterator(Integer[] intInput) {
|
77
|
|
-// Integer[] retArr = new Integer[intInput.length];
|
78
|
|
-//
|
79
|
|
-// Iterator<Integer> iterator = new Iterator<Integer>() {
|
80
|
|
-// public boolean hasNext(int intValue) {
|
81
|
|
-// return intValue == null ? true : false;
|
82
|
|
-// }
|
83
|
|
-//
|
84
|
|
-// public Integer next() {
|
85
|
|
-// return null;
|
86
|
|
-// }
|
87
|
|
-//
|
88
|
|
-// public void remove() {
|
89
|
|
-//
|
90
|
|
-// }
|
91
|
|
-// }
|
92
|
|
-// return retArr;
|
93
|
|
-// }
|
|
74
|
+ public int[] copyArrayByIterator(Integer[] intInput) {
|
|
75
|
+ int[] retArr = new int[intInput.length];
|
|
76
|
+ List<Integer> list = Arrays.asList(intInput);
|
|
77
|
+ Iterable<Integer> iterable = list;
|
|
78
|
+ Iterator<Integer> iterator = iterable.iterator();
|
|
79
|
+
|
|
80
|
+ int index = 0;
|
|
81
|
+ while (index < intInput.length){
|
|
82
|
+ retArr[index] = iterator.next();
|
|
83
|
+ index++;
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ return retArr;
|
|
87
|
+ }
|
94
|
88
|
|
95
|
89
|
public int[] copyArrayByLoop(int[] ints){
|
96
|
90
|
int[] retArr = new int[ints.length];
|
|
@@ -346,19 +340,25 @@ public class Arraz {
|
346
|
340
|
}
|
347
|
341
|
|
348
|
342
|
public int[] sortArrayIntoEvensThenOdds(int[] arr) {
|
349
|
|
- ArrayList<Integer> even = new ArrayList<>();
|
350
|
|
- ArrayList<Integer> odd = new ArrayList<>();
|
351
|
|
- int[] retArr = new int[arr.length];
|
|
343
|
+ ArrayList<Integer> evenList = new ArrayList<>();
|
|
344
|
+ ArrayList<Integer> oddList = new ArrayList<>();
|
|
345
|
+ int retArrLength = arr.length;
|
352
|
346
|
|
353
|
347
|
for (int i: arr) {
|
354
|
348
|
if (i % 2 == 0){
|
355
|
|
- even.add(i);
|
|
349
|
+ evenList.add(i);
|
356
|
350
|
}
|
357
|
351
|
else {
|
358
|
|
- odd.add(i);
|
|
352
|
+ oddList.add(i);
|
359
|
353
|
}
|
360
|
354
|
}
|
361
|
355
|
|
|
356
|
+ return retArr(evenList, oddList, retArrLength);
|
|
357
|
+ }
|
|
358
|
+
|
|
359
|
+ private int[] retArr(ArrayList<Integer> even, ArrayList<Integer> odd, int retArrLength){
|
|
360
|
+ int[] retArr = new int[retArrLength];
|
|
361
|
+
|
362
|
362
|
int index = 0;
|
363
|
363
|
for (int i: even) {
|
364
|
364
|
retArr[index] = i;
|
|
@@ -369,7 +369,6 @@ public class Arraz {
|
369
|
369
|
retArr[index] = i;
|
370
|
370
|
index++;
|
371
|
371
|
}
|
372
|
|
-
|
373
|
372
|
return retArr;
|
374
|
373
|
}
|
375
|
374
|
}
|