zoukankan      html  css  js  c++  java
  • 顺序表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();
    
        }   
    }
  • 相关阅读:
    SQL 测试
    atoi的实现
    python基础3 ---python数据类型二
    python基础2 ---python数据类型一
    python基础1 ---python简介
    shell编程3 ---流程控制语句
    shell编程2 ---条件判断语句
    oldboyshell编程扩展内容
    nfs服务器
    shell编程1
  • 原文地址:https://www.cnblogs.com/yldf/p/11900138.html
Copyright © 2011-2022 走看看