-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_median_sorted.cpp
More file actions
52 lines (44 loc) · 1.05 KB
/
find_median_sorted.cpp
File metadata and controls
52 lines (44 loc) · 1.05 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
#include<iostream>
#include<vector>
//using namespace std;
class Solution {
public:
int cmp (int a,int b) {
if (a > b) return 1;
return 0;
}
std::vector<int>* mergeArray (int A[], int m, int B[], int n) {
std::vector<int>* temp = new std::vector<int>();
int i = 0;
int j = 0;
while(i < m && j < n) {
if (1 == cmp(A[i],B[j]) ) {
temp->push_back(B[j]);
j++;
}else {
temp->push_back(A[i]);
i++;
}
}
if(i < m) {
temp->push_back(A[i]);
i++;
}
else if(j < n) {
temp->push_back(B[j]);
j++;
}
return (temp);
}
double findMedianSortedArrays(int A[], int m, int B[], int n)
{
std::vector<int>* temp = mergeArray(A,m,B,n);
int len = temp->size();
}
};
int main () {
Solution* sol = new Solution();
int A[] = {1,2,3,4,6,7};
int B[] = {2,7,8,9,12};
sol->findMedianSortedArrays(A,6,B,5);
}