Find the 2nd largest element in an array with minimum number of comparisons

后端 未结 24 1348
清酒与你
清酒与你 2020-11-28 01:03

For an array of size N, what is the number of comparisons required?

24条回答
  •  甜味超标
    2020-11-28 01:20

        int[] int_array = {4, 6, 2, 9, 1, 7, 4, 2, 9, 0, 3, 6, 1, 6, 8};
        int largst=int_array[0];
        int second=int_array[0];
        for (int i=0; ilargst) { 
                second=largst;
                largst=int_array[i];
            }  
            else if(int_array[i]>second  &&  int_array[i]

提交回复
热议问题