https://www.geeksforgeeks.org/smallest-difference-pair-values-two-unsorted-arrays/
i have to make an assignment similar to this using recursive and vector and i cannot use sort, in this particular assignment.
example:
A = {1, 2, 6}, b = {0, 1, 3, 4, 5}, the output should be diff(a, b) = 2
i done try alot things and im lost and i need help please only give me advice and try not to give me the answer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
int diff_with_recrusive(const std::vector<int>& a, const std::vector<int>& b, int m, int n)
{
int minDiff = INT_MAX;
m=a.size();
n=b.size();
for(int i=0; i<m; i++) {
for(int j=0; j<n j++) {
if(abs(a[i] - b[j]) < minDiff) {
minDiff = abs(a[i] - b[j]);
}
}
}
return minDiff;
}
int diff_recursive(const std::vector<int>& a, const std::vector<int>& b)
{
return diff_with_recrusive(a, b, a.size(), b.size());
}
| |
Last edited on