面试题64:写一个函数并找出在一个整数数组中第二大的数
答:编写程序如下。(微软公司题目)
01 const int MINNUMBER=-32767; 02 int find_sec_max(int data[],int count) 03 { 04 int maxnumber=data[0]; 05 int sec_max=MINNUMBER; 06 for(int i=1;i<count;i++) 07 { 08 if(data>maxnumber) 09 { 10 sec_max=maxnumber; 11 maxnumber=data; 12 } 13 else 14 { 15 if(data>sec_max) 16 sec_max=data; 17 } 18 } 19 return sec_max; 20 }