zoukankan      html  css  js  c++  java
  • 数组长度改变方法

    package com.lovo.array;
    
    public class SuperIntArray {
    	//属性
    	public int[] array;
    	
    	private int index;//代表两层含义:1、下一个元素所在的下标;2、已经放了多少个元素。
    	
    	public SuperIntArray(){
    		this.array = new int[20];
    	}
    	
    	
    	//行为
    	//放入元素
    	public void add(int num){
    		if(this.index >= this.array.length){
    			//扩容
    			int[] newArray = new int[this.array.length + 10];
    			System.arraycopy(this.array, 0, newArray, 0, this.array.length);
    			this.array = newArray;
    		}
    		//把传入的num放入到array当中去
    		this.array[index] = num;
    		this.index++;
    	}
    	
    	//得到某个元素
    	public int get(int index){
    		return 0;
    	}
    	
    	//修改某个元素
    	public void set(int index,int newNum){
    		
    	}
    	
    	//删除某个位置的元素
    	public void remove(int index){
    		
    	}
    	
    	//获得元素的个数
    	public int size(){
    		return 0;
    	}
    	
    }
    

    实现:

    package com.lovo.array;
    
    public class TestArray {
              public static void main(String[] args) {
    	// TODO Auto-generated method stub
    	SuperIntArray sa = new SuperIntArray();
    	for(int i = 0; i < 100031; i++){
    			sa.add(i);
    	}
             }
    
    }
    
  • 相关阅读:
    右滑返回上一页
    flutter 启动图
    [题解]NOIP2014
    [题解]LightOJ1289 LCM from 1 to n
    [题解]CodeForces442B Andrey and Problem
    [题解]HDU4035 Maze
    [题解]CodeForces#290(div1)
    SCP-bzoj-1078
    SCP-bzoj-1068
    SCP-bzoj-1054
  • 原文地址:https://www.cnblogs.com/134-hw/p/6130772.html
Copyright © 2011-2022 走看看