顺序表java实现

public class SeqList
{
    Object[] data;
    int maxSize;
    int length;

    public SeqList(int maxSize)
    {
        this.maxSize = maxSize;
        this.data = new Object[this.maxSize];
        this.length = 0;
    }

    public boolean isEmpty()
    {
        return this.length == 0 ;
    }

    public boolean isFull()
    {
        return this.length == this.maxSize;
    }

    public boolean listInsert(int index, Object e)
    {
        if(this.isFull()) return false;
        if(index>length  || index<0) return false;
        for(int i=this.length-1;i>=index;--i)
            this.data[i+1] = this.data[i];
        this.data[index] = e;
        this.length ++;
        return true;
    }

    public boolean listDelete(int index, Object e)
    {   
        if(index<0 || index>=this.length)
            return false;
        if(this.isEmpty()) 
            return false;

        for(int i=index+1;i<=this.length-1;i++)
            this.data[i-1] = this.data[i];
        return true;
    }

    public void printList()
    {
            for(int i=0;i<this.length;i++)
                System.out.print(this.data[i]+"	");
            System.out.println();
    }

    public static void main(String[] args)
    {
            SeqList S = new SeqList(100);
            for(int i=0;i<10;i++)
                S.listInsert(i,i+1);
            S.printList();

    }   
}
原文地址:https://www.cnblogs.com/yldf/p/6249872.html