multiple comparisons

In comparing four numbers, is there a simple way to determine which number is the smallest? I'd rather not do a series of if/then statements...

Thanks!
If they are in a container, look up the STL min_element algorithm in the Reference section.
Otherwise min( a, b, c, d ) == min( min( a, b ), min( c, d ) )

I'll try the "min" suggestion -- thanks!

I realize that I should have been more clear on what I'm doing.

(pseudo-code)
int myArray1[11] = {2, 3, 11, 6, 7...etc...}
int myArray2[11] = {1, 5, 9, 10, 0...etc...}
int myArray3[11] = {6, 11, 9, 3, 1...etc...}

I want to find the "smallest" array based on the which array has smaller numbers to the left. So, the program should look at myArray1[0], myArray2[0] and myArray3[0] and choose myArray2, because 1 is smaller than 2 or 6.

That doesn't seem terribly complicated -- and I'm guessing that the min method from jsmith might do it.

But, I also want to allow for the possibility of "ties." If we also include:
int myArray4[11] = {1, 3, 10, 4, 6...etc...}
Then, myArray2[0] and myArray4[0] are both the smallest. So look at myArray2[1] and myArray4[1]. Then choose myArray4...

Will min do this for me? I've been trying it with if/then statements, but (as I alluded to in my original post), it gets pretty hairy pretty quickly!

Thanks again!!
Last edited on
min() won't do it then. You need more logic to detect and deal with ties.
Topic archived. No new replies allowed.