集册 Java实例教程 反转数组(与字符串反转的实现相同

反转数组(与字符串反转的实现相同

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

489
反转数组(与字符串反转的实现相同


//package com.nowjava;


public class Main {/** 时代Java公众号 提 供 **/

    /**

     * Reverses an array (Same implementation as string reversal

     * @param list

     */

    public static void reverseArray(Character[] list) {

        reverseArrayFromToPosition(list, 0, list.length - 1);

    }


    public static void reverseArrayFromToPosition(Character[] list,

            int fromPos, int toPos) {

        //System.out.println("from Pos: " + fromPos + " to Pos" + toPos);

        int numIterations = (int) Math.ceil((toPos - fromPos) / 2.0);

        for (int x = fromPos; x < fromPos + numIterations; x++) {
        /*
        N o  w  J a v a . c o
展开阅读全文