Title: Move a number of elements at the beginning of an array to the end of the array, called a rotating array, enter a rotation of an incrementally sorted array, and output the smallest element of the rotated array. For example, the array {3,4,5,1,2} is a rotation of the array {1,2,3,4,5}, and the minimum value of the array is 1;
1#include <stdio.h>2 intMininorder (intR[],intP1,intp2)3 {4 intresult =R[P1];5 for(inti = p1 +1; I <= p2; i++)6 {7 if(R[i] <result)8result =R[i];9 }Ten returnresult; One } A intMin (intR[],intlength) - { - if(r = = NULL | | length <=0) the return 0; - intP1 =0; - intP2 = length-1; - intMID =P1; + while(R[p1] >=R[P2]) - { + if(P2-P1 = =1) A { atMID =P2; - Break; - } -Mid = (P1 + p2)/2; - if(R[P1] = = R[p2] && R[mid] = =R[P2]) - returnMininorder (R, p1, p2); in if(R[mid] >=R[P1]) -P1 =mid; to Else if(R[mid] <=R[P2]) +P2 =mid; - } the returnR[mid]; * } $ Panax Notoginseng intMain () - { the inta[8] = {1,1,1,0,1 }; +printf"%d\n", Min (A,5)); A return 0; the}View Code
Minimum number of rotating arrays--Sword