集册 Java实例教程 数组列表中的移位元素

数组列表中的移位元素

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

426
数组列表中的移位元素
/*
来 自*
 时   代    Java - nowjava.com
*/

/*

Holyoke Framework: library for GUI-based database applications

This file Copyright (c) 2006-2008 by Robert Fischer


This program is free software: you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.


This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

GNU General Public License for more details.


You should have received a copy of the GNU General Public License

along with this program.  If not, see <http://www.gnu.org/licenses/>.

 */

//package com.nowjava;

import java.util.*;


public class Main {

    public static void shift(ArrayList al, int ix, int n, int shift) {

        //   int oldsize = al.size();

        //   int lastix = ix + n + shift;   // last index (+1) of last item being shifted

        if (shift > 0) {

            //      while (al.size() < lastix) al.add(null);   // potentially add...

            for (int i = n - 1; i >= 0; --i)

                al.set(ix + i + shift, al.get(ix + i));

        } else {

            for (int i = 0; i < n; ++i)

                al.set(ix + i + shift, al.get(ix + i));

        }

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

    
展开阅读全文