To achieve the minimum value of the maximum value of the array, brute force method is much easier. This paper focuses on the principle of experiencing the idea of divided law:
1 intMainvoid)2 {3 voidMaxmin (intA[],intLowintHighintmaxmin[2]);4 inta[Ten],maxmin[2];5 6printf"Enter Ten integer numbers:\n");7 for(intI=0;i<Ten; i++)8scanf"%d", A +i);9 TenMaxmin (A,0,9, maxmin); Oneprintf"\nmaximum:%d\nminimum:%d\n", maxmin[0],maxmin[1]); ASystem"Pause"); - return 1; - } the - //to find the maximum and minimum values of the array by the method of divide and conquer - voidMaxmin (intA[],intLowintHighintmaxmin[2]) - { + intmid; - intmaxmin1[2],maxmin2[2]; + A if(high==Low ) at { -maxmin[0]=A[low]; -maxmin[1]=A[low]; - return; - } - if(high==low+1) in { - if(a[high]>A[low]) to { +maxmin[0]=A[high]; -maxmin[1]=A[low]; the}Else * { $maxmin[0]=A[low];Panax Notoginsengmaxmin[1]=A[high]; - } the return; + } A Else the { +Mid = (High+low)/2; - maxmin (a,low,mid,maxmin1); $Maxmin (a,mid+1, high,maxmin2); $ if(maxmin1[0]>maxmin2[0]) -maxmin[0]=maxmin1[0]; - Else themaxmin[0]=maxmin2[0]; - //MinimumWuyi if(maxmin1[1]<maxmin2[1]) themaxmin[1]=maxmin1[1]; - Else Wumaxmin[1]=maxmin2[1]; - } About}
The minimum value of the maximum value of the array by the method of divide and conquer