View code
Namespace Leleapplication1 { /// <Summary> /// Microsoft interview questions, an integer Array {1, 2, 3 ......} /// Select a number and place the number at the end of the array, /// A number larger than this value is arranged progressively at the front end of the array. /// Add a number smaller than the number of times to the end, and sort them in ascending order. /// </Summary> Class Program { Static Void Main ( String [] ARGs ){ // Set the array value to {1-20} Int [] Intarr = New Int [ 20 ]; For ( Int I =0 ; I <intarr. length; I ++ ) {Intarr [I] = I + 1 ;} // Obtain the number selected Console. writeline ( " Selectelements (1-20 ): " ); Int Selectelement = Convert. toint32 (console. Readline (); func1 (intarr, selectelement); console. Read ();} /// <Summary> /// Array of output reorganization Sequence /// </Summary> /// <Param name = "arr"> </param> /// <Param name = "selectelement"> </param> Public Static Void Func1 ( Int [] Arr, Int Selectelement ){ Int Index =- 1 ; Swap (ARR, 0 , Arr. Length- 1 ); For ( Int I = 0 ; I <arr. length; I ++ ){ If (ARR [I] = Selectelement) Index =I;} swap (ARR, 0 , Index- 1 ); Swap (ARR, index, arr. Length - 1 ); For ( Int I = 0 ; I <arr. length; I ++ ) {Console. writeline (ARR [I]. tostring ());}} /// <Summary> /// Value of a segment in the inverted Array /// </Summary> /// <Param name = "arr"> </param> /// <Param name = "beginindex"> </param> /// <Param name = "endindex"> </param> Public Static Void Swap ( Int [] Arr,Int Beginindex, Int Endindex ){ Int Temp =- 1 ; Int Swaptimes =- 1 ; If (Endindex-beginindex + 1 ) % 2 = 0 ) Swaptimes = (Endindex-beginindex + 1 )/ 2 ; Else Swaptimes = (Endindex-beginindex )/ 2 ; For ( Int I = 0 ; I <swaptimes; I ++ ) {Temp = Arr [beginindex + I]; arr [beginindex + I] = arr [endindex-I]; arr [endindex -I] = Temp ;}}}}