算法 - 数组位移

    public void reindexArray(int[] arr, int step) {     
        int len = arr.length;
        int s = step % len;
        int[] a = new int[len];
        for (int i = 0; i < len; i++) {
            if(i+s<arr.length){
                a[i+s] = arr[i];
            }else{
                a[i+s-len] = arr[i];
            }
        }
        for (int i : a) {
            System.out.println(i);
        }
    }

 

posted @ 2017-05-04 12:45  测试人生-  阅读(537)  评论(0编辑  收藏  举报