Right
Find Min with Recursion
Yes, returning the index is a good solution:
unsigned recursive_min(double *data, unsigned n) {
if (n <= 1) // [EDIT: Was `n == 1'. Thanks, rip-off.]
return n - 1; // returns -1 for an empty input
unsigned left_index = recursive_min(data, n/2);
unsigned right_index = recursive_min(data + n/2, n - n/2) + n/2;
return data[left_index] < data[right_index] ? left_index : right_index;
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement