数组动态分配(非动态数组) 2013_7_25_实验室

数组实现动态的内存分配,也就是说数组的大小是由程序外部决定的,

public class Array {
    private int temp[];
    private int foot;
    public Array(int len){
        if(len > 0){
            this.temp = new int[len];
        }else{
            this.temp = new int[1];
        }
    }
    public boolean add(int i){
        if(this.foot < this.temp.length){
            this.temp[foot] = i;
            return true;
        }else{
            return false;
        }
    }
    public int[] getArray(){
        return this.temp;
    }

}

 

 

posted on 2013-07-25 16:22  I忒美咖  阅读(230)  评论(1编辑  收藏  举报

导航