Title Description: moves a number of elements at the beginning of an array to the end of an array, called a rotation of an array. Enter the rotation of an incrementally sorted array, outputting the smallest element of the rotated array.
For example: The array {3,4,5,1,2} is a rotation of {1,2,3,4,5}, and the smallest element of the array is 1.
Analysis: 650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/83/AD/wKioL1d6I02S_u47AABlJI2p4WM108.png "title=" 1. PNG "style=" Float:none; "alt=" Wkiol1d6i02s_u47aablji2p4wm108.png "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/83/AD/wKioL1d6I6mBDOUbAACqQlZMvtc508.png "title=" 2.png " Style= "Float:none;" alt= "Wkiol1d6i6mbdoubaacqqlzmvtc508.png"/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/83/AD/wKioL1d6JCmzpGhhAAA_rgK0PcM895.png "style=" float: none; "title=" 3-1.png "alt=" Wkiol1d6jcmzpghhaaa_rgk0pcm895.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/83/AE/wKiom1d6JCnjk830AAAacK-tef4264.png "style=" float: none; "title=" 3-2.png "alt=" Wkiom1d6jcnjk830aaaack-tef4264.png "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/83/AE/wKiom1d6JHzyagMiAAFF9WWZnVw523.png "style=" float: none; "title=" 4.png "alt=" Wkiom1d6jhzyagmiaaff9wwznvw523.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/83/AD/wKioL1d6JHuQJhiFAACQKUJQYjc925.png "title=" 5.png " Style= "White-space:normal;float:none;" alt= "Wkiol1d6jhuqjhifaacqkujqyjc925.png"/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/83/AE/wKiom1d6JNaTY4w8AAExPZ0Fhc0615.png "style=" float: none; "title=" 6.png "alt=" Wkiom1d6jnaty4w8aaexpz0fhc0615.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/83/AD/wKioL1d6JNbDoPPaAABLDJk250A540.png "style=" float: none; "title=" 7.png "alt=" Wkiol1d6jnbdoppaaabldjk250a540.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/83/AE/wKiom1d6JP7jFWjXAAB4gaLULXU375.png "title=" 8.png " alt= "Wkiom1d6jp7jfwjxaab4galulxu375.png" style= "float:none;"/>
Int min (int* numbers, int length) { if (Numbers == NULL | | length <= 0) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;THROW&NBSP;NEW&NBSP;STD:: Exception ("Invalid parameters"); int index1 = 0; int index2 = length - 1; int indexmid = index1; while (Numbers[index1] >= numbers[index2]) { // if Index1 and Index2 point to adjacent two numbers, // index1 points to the last digit of the first incrementing Subarray, // index2 points to the first number of the second Subarray, which is the smallest number if in the array (index2 - &NBSP;INDEX1&NBSP;==&NBSP;1) { indexmid = index2; break; } // if the subscript is index1, Index2, and Indexmid point to a three number equal, // You can only search in sequence indexmid = (INDEX1&NBSP;+&NBSP;INDEX2) / 2; // narrowing the look-up range if (numbers[indexmid] >= NUMBERS[INDEX1]) index1 = Indexmid; else if (numbers[indexmid] <= NUMBERS[INDEX2]) index2 = indexmid; } return numbers[indexmid];}
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/83/AD/wKioL1d6KGGB_mnqAADrnKO10-E939.png "style=" float: none; "title=" 9.png "alt=" Wkiol1d6kggb_mnqaadrnko10-e939.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/83/AD/wKioL1d6KGKA-7BXAADr7gcqcZ0080.png "style=" float: none; "title=" 10.png "alt=" Wkiol1d6kgka-7bxaadr7gcqcz0080.png "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/83/AE/wKiom1d6KGKz8QINAABCI9ulaT4666.png "style=" float: none; "title=" 12.png "alt=" Wkiom1d6kgkz8qinaabci9ulat4666.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/83/AD/wKioL1d6KGPj6lxXAABc_nQ3jS8470.png "style=" float: none; "title=" 13-1.png "alt=" Wkiol1d6kgpj6lxxaabc_nq3js8470.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/83/AE/wKiom1d6KGPysVqlAACRjL2OWSg277.png "style=" float: none; "title=" 13-2.png "alt=" Wkiom1d6kgpysvqlaacrjl2owsg277.png "/>
Int min (int* numbers, int length) { if (Numbers == NULL | | length <= 0) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;THROW&NBSP;NEW&NBSP;STD:: Exception ("Invalid parameters"); int index1 = 0; int index2 = length - 1; int indexmid = index1; while (Numbers[index1] >= numbers[index2]) { // if Index1 and Index2 point to adjacent two numbers, // index1 points to the last digit of the first incrementing Subarray, // index2 points to the first number of the second Subarray, which is the smallest number if in the array (index2 - &NBSP;INDEX1&NBSP;==&NBSP;1) { indexmid = index2; break; } // if the subscript is index1, Index2, and Indexmid point to a three number equal, // Only sequential lookup indexMid = (INDEX1&NBSP;+&NBSP;INDEX2) / 2; if (numbers[index1] == numbers[index2] &&&NBSP;NUMBERS[INDEXMID]&NBSP;==&NBSP;NUMBERS[INDEX1]) return mininorder (NUMBERS,&NBSP;INDEX1,&NBSP;INDEX2); // narrowing the look-up range if (numbers[ INDEXMID]&NBSP;>=&NBSP;NUMBERS[INDEX1]) index1 = indexmid;&Nbsp; else if (Numbers[indexmid] <= numbers[index2]) index2 = indexMid; } return numbers[indexmid];} Int mininorder (int* numbers, int index1, int index2) { int result = numbers[index1]; for (int i = index1 + 1; i <= index2; ++i) { if (Result > numbers[i]) result = numbers[i]; } return result;}
650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0016.gif "alt=" J_0016.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0016.gif "alt=" J_0016.gif "/>650" this.width=650; "src=" http://img.baidu.com/hi/ Jx2/j_0016.gif "alt=" J_0016.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0016.gif "alt=" j_ 0016.gif "/>650) this.width=650;" src= "Http://img.baidu.com/hi/jx2/j_0016.gif" alt= "J_0016.gif"/>650 " this.width=650, "src=" Http://img.baidu.com/hi/jx2/j_0016.gif "alt=" J_0016.gif "/>650" this.width=650; "src=" http ://img.baidu.com/hi/jx2/j_0016.gif "alt=" J_0016.gif "/>650" this.width=650; "src=" http://img.baidu.com/hi/jx2/j _0016.gif "alt=" J_0016.gif "/>650" this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0016.gif "alt=" j_0016.gif "/>650) this.width=650;" src= "Http://img.baidu.com/hi/jx2/j_0016.gif" alt= "J_0016.gif"/>650 "this.width=650;" Src= "Http://img.baidu.com/hi/jx2/j_0016.gif" alt= "J_0016.gif"/>650) this.width=650; " Src= "Http://img.baidu.com/hi/jx2/j_0016.gif" alt= "J_0016.gif"/>650) this.width=650; src= http://img.baidu.com /hi/jx2/j_0016.gif "alt=" J_0016.gif "/>
This article is from the "11408774" blog, please be sure to keep this source http://11418774.blog.51cto.com/11408774/1795688
Rotate the smallest number in an array