Question: I need help translating this C++ for-loop function into a rescursive function. This is the function I have: int smallestDifference_optimized(const std::vector & a, const std::vector
I need help translating this C++ for-loop function into a rescursive function.
This is the function I have:
int smallestDifference_optimized(const std::vector
int tmp=100000; int total=0; if(a.size()==b.size()||a.size() } return total; } I need to implement this in a recurstive way. This will be the shell of it: int smallestDifference_recursive_utility(const std::vector } int smallestDifference_recursive(const std::vector The main.cpp for this program is: #include #include "smallest_difference.h" typedef int (*differenceFunction)(const std::vector void printSet(const std::vector void findDifference(const std::vector int main(int argc, char** argv) { if (argc != 3) { std::cout << "Usage: " << argv[0] << " a-sequence-file b-sequence-file" << std::endl; return 0; } std::ifstream aIn(argv[1]); std::ifstream bIn(argv[2]); std::vector std::copy(std::istream_iterator std::cout << "Looking for the smallest difference between the following sets:" << std::endl; printSet(a, "a"); printSet(b, "b"); std::cout << "Using Recursive function: "; findDifference(a, b, smallestDifference_recursive); std::cout << std::endl; std::cout << "Using Amortized function: "; findDifference(a, b, smallestDifference_amortized); std::cout << std::endl; std::cout << "Using Optimized function: "; findDifference(a, b, smallestDifference_optimized); std::cout << std::endl; return 0; } The smallest_difference.h file is: #pragma once #ifndef __SMALLEST_DIFFERENCE_H__ #define __SMALLEST_DIFFERENCE_H__ #include int smallestDifference_recursive(const std::vector
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
