-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathss_sorted_merge.cpp
More file actions
70 lines (53 loc) · 1.07 KB
/
ss_sorted_merge.cpp
File metadata and controls
70 lines (53 loc) · 1.07 KB
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
66
67
68
69
70
#include <iostream>
using namespace std;
int sorted_merge(int* a, int* b, int l_a){
int l_b = 3;
int l_m = 7;
l_a -= 1;
while(l_m > -1){
if(l_a > -1 and a[l_a] > b[l_b]){
a[l_m] = a[l_a];
l_a -= 1;
}
else if (l_b > -1){
a[l_m] = b[l_b];
l_b -= 1;
}
l_m -= 1;
}
}
int main(){
int b[] = {1,3,5,7};
int a[] = {0,2,4,6,-1,-1,-1,-1};
int l_a = sizeof(a)/sizeof(a[0]);
int l_b = sizeof(b)/sizeof(b[0]);
l_a -= l_b;
sorted_merge(a, b, l_a);
for(int i=0; i<8; i++){
cout << a[i] << endl;
}
return 0;
}
// int main(){
// int size = 4;
// int b[] = {1,3,5,7};
// int* a = new int[size];
// int l_a = size;
// int l_b = sizeof(b)/sizeof(b[0]);
// cout << l_a << endl;
// cout << l_b << endl;
// for(int i=0; i<l_a; i++){
// a[i] = 2*i;
// cout << a[i] << endl;
// }
// a = (int*)malloc((l_a+l_b)*sizeof(int));
// for(int i=l_a; i<l_a+l_b; i++){
// a[i] = -1;
// cout << a[i] << endl;
// }
// for(int i=0; i<l_a+l_b; i++){
// cout << a[i] << endl;
// }
// // cout << sorted_merge(a, b, l_a) << endl;
// return 0;
// }