Moves a set of arrays to the right K-bit, at the end of which to transpose moves to the beginning of the array, where n is the size of the arrays, 0<k<n

Source: Internet
Author: User

The following is done using the A array itself:

 Packagearray element K-bit right shift;/*** The array moves to and from the K-bit. 0<k<n * *@authorSeeclanukyo moves a set of arrays to the right by the K-bit, the end of which to transpose moves to the beginning of the array, where n is the size of the arrays, 0<k<n*/ Public classArraymovek { Public Static voidMain (string[] args) {intK = 3; int[] A = {1, 2, 3, 4, 5 };            Arraymovek (A, k); }     Public Static voidArraymovek (int[] A,intk) {//Get length        intL =a.length; //get the maximum subscript value        intMaxindex = L-1; //For loop make end and start change position         for(inti = 0; I < K; i++) {            //gets the value of the array's maximum subscript            intLast =A[maxindex];  for(intj = 0; J < Maxindex; J + +) {                //moves the other elements in the array to the right one bit, and the first time gets the maxindex-j 0 for the maxindex itselfA[MAXINDEX-J] = a[maxindex-1-J]; }            //pass the last value at the end to the beginning of the arrayA[0] =Last ; }        //iterate through the output of a new array         for(intx:a) {System.out.print (x+ " "); }    }}

Here's the second array: (so it's a lot easier)

 Packagearray element K-bit right shift;/*** The array moves to and from the K-bit. 0<k<n * *@authorSeeclanukyo moves a set of arrays to the right by the K-bit, the end of which to transpose moves to the beginning of the array, where n is the size of the arrays, 0<k<n*/ Public classArraymovek { Public Static voidMain (string[] args) {intK = 3; int[] A = {1, 2, 3, 4, 5 };            Arraymovek (A, k); }     Public Static voidArraymovek (int[] A,intk) {//Get length        intL =a.length; //get the maximum subscript value        intMaxindex = L-1; //For loop make end and start change position         for(inti = 0; I < K; i++) {            //gets the value of the array's maximum subscript            intLast =A[maxindex];  for(intj = 0; J < Maxindex; J + +) {                //moves the other elements in the array to the right one bit, and the first time gets the maxindex-j 0 for the maxindex itselfA[MAXINDEX-J] = a[maxindex-1-J]; }            //pass the last value at the end to the beginning of the arrayA[0] =Last ; }        //iterate through the output of a new array         for(intx:a) {System.out.print (x+ " "); }    }}

Moves a set of arrays to the right K-bit, at the end of which to transpose moves to the beginning of the array, where n is the size of the arrays, 0<k<n

Related Article

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.