nickf's algorithm is not the best way to do this. In the worst case, nickf's algorithm does 2 compares per number, for a total of 2n - 2.
We can do a fair bit better. When you compare two elements a and b, if a > b we know that a is not the min, and b is not the maximum. This way we use all of the available information to eliminate as many elements as we can. For simplicity, suppose we have an even number of elements.
Break them into pairs: (a1, a2), (a3, a4), etc.
Compare them, breaking them into a set of winners and losers - this takes n/2 compares, giving us two sets of size n/2. Now find the max of the winners, and the min of the losers.
From above, finding the min or the max of n elements takes n-1 compares. Thus the runtime is:
n/2 (for the initial compares) + n/2 - 1 (max of the winners) + n/2 - 1 (min of the losers) = n/2 + n/2 + n/2 -2 = 3n/2 - 2. If n is odd, we have one more element in each of the sets, so the runtime will be 3n/2
In fact, we can prove that this is the fastest that this problem can be possibly be solved by any algorithm.
An example:
Suppose our array is 1, 5, 2, 3, 1, 8, 4
Divide into pairs: (1,5), (2,3) (1,8),(4,-).
Compare. The winners are: (5, 3, 8, 4). The losers are (1, 2, 1, 4).
Scanning the winners gives 8. Scanning the losers gives 1.