Run
import java.util.Arrays;
public
class Main {
static int arr1[] = new int[]{1, 12, 9, 3, 17, 20};
static int arr2[] = new int[]{2, 3, 8, 13};
static void merge(int m, int n) {
// Iterate through all elements of ar2[] starting from
// the last element
for (int i = n - 1; i >= 0; i--) {
int j, last = arr1[m - 1];
for (j = m - 2; j >= 0 && arr1[j] > arr2[i]; j--) arr1[j + 1] = arr1[j];
// If there was a greater element
if (j != m - 2 || last > arr2[i]) {
arr1[j + 1] = arr2[i];
arr2[i] = last;
}
}
}
// Driver method to test the above function
public
static void main(String[] args) {
merge(arr1.length, arr2.length);
System.out.print("After Merging First Array: ");
System.out.println(Arrays.toString(arr1));
System.out.print("Second Array: ");
System.out.println(Arrays.toString(arr2));
}
}
public static void mergetwosorted(int arr1[],int arr2[]){
int n=arr1.length;
int m=arr2.length;
int i=0;
int j=0;
while(iarr2[j]){
//swap the program
int temp=arr1[i];
arr1[i]=arr2[j];
arr2[j]=temp;
sortedarr2(arr2);
}
i++;
}
System.out.println(Arrays.toString(arr1)+Arrays.toString(arr2));
}
//This is a helping function of mergesorted array
public static void sortedarr2(int arr2[]){
for(int i=0;iarr2[i+1]){
int temp=arr2[i+1];
arr2[i+1]=arr2[i];
arr2[i]=temp;
}
}
} want to more solution so you can check my Github “https://github.com/Palakgupta2002”