Subj : Re: resolving a list of numbers to a range To : comp.programming From : Rob Thorpe Date : Thu Aug 18 2005 03:09 am Espen Suenson wrote: > placid wrote: > > > Hi all, > > > > I was just if anyone knows a way to resolve a list of integers say > > {1,2,3,4,5} into a range that is 1-5? > > Here's an algorithm: > > 1) Find the smallest integer in the list, this is A. > 2) Find the largest integer in the list, this is B. > 3) Return the range A-B. > > One way of doing steps 1 and 2 is to sort the list. Then the smallest > integer will be the first element and the largest integer will be the last > element in the list. There is also Ira Pohl's min/max algorithm, which can do it with 1.5*n comparisons, rather than the 2*n comparisons used above. Search the web/usenet archives for Ira Pohl and min max. Or read "A book on C" by Kelley and Pohl. .