/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http:// **
*****************************************************************/
void FinMaxMin(int nList[], int n)
{
int Min,Max,i,n2;
n2 = n/2;
for (i=0; i<n2; ++i) //二分,较小的放在前一半
{
if(nList[i]>nList[i+n2])
{
int t = nList[i];
nList[i] = nList[i+n2];
nList[i+n2] = t;
}
}
Min = Max = nList[n-1];
for (i=0; i<n2; ++i) //找出极值
{
if (Min>nList[i]) Min = nList[i]; //前一半找
if (Max<nList[i+n2]) Max = nList[i+n2]; //后一半找
}
printf("最大值为%d 最小值为%d\n", Max, Min);
}
此方法来源:腾讯笔试题
" border="0" />[color=white]