I've written a template to return the middle value of 3 distinct parameters. But now I want to re-write it using arrays. How would I go about doing that? Directly below is what I currently have, it and works fine when finding the middle value.
1 2 3 4 5 6 7 8 9
template <class T>
T findmid(T a, T b, T c)
{
if (a>b && a<c || a < b && a>c)
return a;
if (b>a && b<c || b < a&& b>c)
return b;
return c;
}
If there is an array, would it look something like this?...if there is an array (as opposed to 3 distinct parameters) it might look something like this, but I would like help to see if this is right:
Would that find the "middle value" of an array a[i]? I have a grasp on the algorithmic aspect, but I'm having trouble with the execution with arrays. Thanks for any help.