-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_array.java
57 lines (56 loc) · 1.2 KB
/
merge_array.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Input -> 5 5
1 2 3 7 8
9 4 5 6 0
Output -> 0 1 2 3 4 5 6 7 8 9
*/
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int m=scan.nextInt();
int n=scan.nextInt();
int i,j=0,k,temp;
int[] ar1=new int[m];
int[] ar2=new int[n];
int[] res=new int[m+n];
for(i=0;i<m;i++)
{
ar1[i]=scan.nextInt();
System.out.print(ar1[i]+" ");
}
System.out.println();
for(i=0;i<n;i++)
{
ar2[i]=scan.nextInt();
System.out.print(ar2[i]+" ");
}
for(i=0;i<m;i++)
{
res[j]=ar1[i];
j++;
}
for(i=0;i<n;i++)
{
res[j]=ar2[i];
j++;
}
for(i=0;i<j-1;i++)
{
for(k=i+1;k<j;k++)
{
if(res[i]>res[k])
{
temp=res[i];
res[i]=res[k];
res[k]=temp;
}
}
}
System.out.println();
for(i=0;i<j;i++)
System.out.print(res[i]+" ");
}
}