集册 Java实例教程 旋转阵列

旋转阵列

欢马劈雪     最近更新时间:2020-01-02 10:19:05

385
旋转阵列
//来 自 时 代      J a v a   公   众 号 - nowjava.com

//package com.nowjava;


public class Main {

    public static void rotateArray(Integer[] arr, int index, int rotateBy) {


        for (int x = 0; x < arr.length; x++) {

            int newLocation = ((x + rotateBy) - 1) % arr.length;

            swapValues(arr, x, newLocation);

        }

    }


    /**

     * Will swap the values between the given input index params

     * 

     * @param array

     * @param index

     * @param otherIndex

     * 

     */
     /**
     来 自 n  o  w  j  a  v  a . c o m
     **/

    public static <T> void swapValues(T array[], 
展开阅读全文