题目:求出数组中第二大的数,要求时间为O(n),其中n为数组的长度
代码如下:
int _tmain(int argc, _TCHAR* argv[])
{
int a[]={2,2,3,5,-3,9};
int temp = a[0];
int min = -1;
for( int index = 1; index < 6; index++)
{
if(temp < a[index])
{
min = temp;
temp = a[index];
}
}
printf("%d\n",min);
return 0;
}