-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort&merge.c
65 lines (65 loc) · 1.07 KB
/
sort&merge.c
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
58
59
60
61
62
63
64
65
#include <stdio.h>
#define MAX_SIZE 100
int temp, i, j;
void swap(int *xp, int *yp)
{
temp = *xp;
*xp = *yp;
*yp = temp;
}
void sort(int arr[], int n)
{
for (i=0; i<n-1; i++)
{
for (j=0; j<n-i-1; j++)
{
if (arr[j] > arr[j + 1])
{
swap(&arr[j], &arr[j + 1]);
}
}
}
}
void main()
{
int n, l, k;
int arr1[MAX_SIZE], arr2[MAX_SIZE], outarr[MAX_SIZE];
printf("Enter the size of the 1st array: ");
scanf("%d", &n);
printf("Enter the Elements of the First Array: \n");
for(i=0; i<n; i++)
{
scanf("%d",&arr1[i]);
}
printf("Enter the size of the 2nd array: ");
scanf("%d", &l);
printf("Enter the Elements of the Second Array: \n");
for(k = 0;k<l;k++)
{
scanf("%d",&arr2[k]);
}
for(i=0;i<n+l;i++)
{
if(i<n)
{
outarr[i]=arr1[i];
}
else
{
outarr[i]=arr2[i-n];
}
}
printf("The Merged Array: { ");
for(i=0;i<n+l;i++)
{
printf("%d ",outarr[i]);
}
printf("}\n");
sort(outarr,n+l);
printf("Sorted array in Ascending Order: { ");
for (i = 0; i < n+l; i++)
{
printf("%d ", outarr[i]);
}
printf("}\n");
}