Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int[] merge(int[] array1, int[] array2){
- int[] fin = new int[array1.length+array2.length];
- int count = 0;
- int lowNum = 100000;
- int lowPos = 0;
- int temp = 0;
- for (int h=0; h<fin.length; h++){
- if ((count<array1.length)&&(count<array2.length)){
- if((h%2) == 0){
- fin[h] = array1[count];
- } else {
- fin[h] = array2[count];
- count++;
- };
- } else if ((!(count<array1.length))&&(count<array2.length)){
- fin[h] = array2[count];
- count++;
- } else if ((count<array1.length)&& (!(count<array2.length))){
- fin[h] = array1[count];
- count++;
- };
- };
- count = 0;
- while(count<fin.length){
- lowNum = 1000000;
- for(int i=count; i<fin.length; i++){
- if(fin[i]<lowNum){
- lowNum = fin[i];
- lowPos = i;
- };
- };
- temp = fin[lowPos];
- fin[lowPos] = fin[count];
- fin[count] = temp;
- count++;
- };
- return fin;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement