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

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

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

24条回答
  •  抹茶落季
    2020-11-28 01:16

    #include
    main()
    {
            int a[5] = {55,11,66,77,72};
            int max,min,i;
            int smax,smin;
            max = min = a[0];
            smax = smin = a[0];
            for(i=0;i<=4;i++)
            {
                    if(a[i]>max)
                    {
                            smax = max;
                            max = a[i];
                    }
                    if(max>a[i]&&smax

提交回复
热议问题