B*********h 发帖数: 800 | 1 ☆─────────────────────────────────────☆
anyfun (anyfun?) 于 (Sat Jan 20 21:46:28 2007) 提到:
find an algorithm for finding the min and max of n numbers by using fewer
than 3n/2 comparisions. ^_^
☆─────────────────────────────────────☆
newnewlife (newlife) 于 (Sat Jan 20 22:04:47 2007) 提到:
Let's try this way:
int max,min;
min=max=a[0];
int minIndex=0,maxIndex=0;
for(int i=1; i < n;i+=2)
{
int bigger=a[i-1],smaller=a[i];
int biggerIndex=i-1, smallerIndex=i;
if(a[i-1] < a[i])
bi |
|