Skip to content

Commit 65f3be5

Browse files
authored
Add files via upload
1 parent af41039 commit 65f3be5

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Coding/mergeKArrays.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
#define N 4
5+
6+
void printArray(int arr[], int size)
7+
{
8+
for (int i = 0; i < size; i++)
9+
cout << arr[i] << " ";
10+
}
11+
12+
13+
void mergeKArrays(int arr[][N], int a, int output[])
14+
{
15+
int c = 0;
16+
17+
for (int i = 0; i < a; i++) {
18+
for (int j = 0; j < N; j++)
19+
output = arr[i][j];
20+
}
21+
22+
sort(output, output + N * a);
23+
}
24+
25+
// Driver's code
26+
int main()
27+
{
28+
int arr[][N] = { { 2, 6, 12, 34 },
29+
{ 1, 9, 20, 1000 },
30+
{ 23, 34, 90, 2000 } };
31+
int K = sizeof(arr) / sizeof(arr[0]);
32+
33+
int output[N * K];
34+
35+
mergeKArrays(arr, 3, output);
36+
37+
cout << "Merged array is " << endl;
38+
printArray(output, N * K);
39+
40+
return 0;
41+
}

0 commit comments

Comments
 (0)