Hello,
I am trying to write a template for finding the middle of 3 values, and I am going to call it the "median". For example, the median of {1, 0, 2} is 1. The median of {"abc", "ghi", "def"} is "def". Any help would be great.
Thanks Frank
Printable View
Hello,
I am trying to write a template for finding the middle of 3 values, and I am going to call it the "median". For example, the median of {1, 0, 2} is 1. The median of {"abc", "ghi", "def"} is "def". Any help would be great.
Thanks Frank
if you are only having 3 inputs then all you need are a couple of comparisons to see which one is greater than one but not greater than another...
Right, I understand if it is just integers. But what if it is like the alphabet example. abc def ghi, where def is the middle one?
Thanks
if they are stl strings then you can compare them the same way but old c-style strings you will need to use strcmp()
place the strings in an array.
sort the strings into alphabetical order
determine which index of the array is the median index
the string stored in the median index of the array is the median string.