Sep 19, 2016 04:02 PM
(This post was last modified: Sep 19, 2016 04:03 PM by Dyst0pia.)
I need to make 1 array out of two different arrays and then sort the new array, I've done it this way and it works perfectly but I keep thinking that its not the most effective way to do it.
Does anyone have any input on how I can optimize this code?
Does anyone have any input on how I can optimize this code?
PHP Code
<?php
public static void fade() {
int array1[] = {131, 42, 3, 54, 5, 6, 6, 8, 9, 32};
int array2[] = {5, 6, 741, 55, 25, 22, 666, 6, 1, 5};
int arrayMerged[] = new int[(array1.length + array2.length)];
int count = 0;
int swap;
// Joins the two arrays together
for (int i = 0; i < arrayMerged.length; i++) {
if (i <= array1.length-1) {
arrayMerged[i] = array1[i];
} else if (i >= array1.length-1) {
arrayMerged[i] = array2[count];
count++;
}
}
// Sorts the new array accordingly
for (int k = 0; k < arrayMerged.length; k++) {
for (int j = k + 1; j < arrayMerged.length ; j++) {
if (arrayMerged[k] > arrayMerged[j]) {
swap = arrayMerged[k];
arrayMerged[k] = arrayMerged[j];
arrayMerged[j] = swap;
}
}
System.out.println(arrayMerged[k]);
}
}


