Microsoft interview questions, inverted Array

Source: Internet
Author: User
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 ;}}}} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.