データ構造のArayList


package MYArrayList;
/**
 * 
 * @author zz384dian
 * @time 2018-2-15
 * @param 
 * @cotent ArrayList   
 */
public class MyArrayList {

	private Integer size;
	private Object objs[];
	
	public MyArrayList(){
		this(10);
	}
	
	public MyArrayList(Integer size){
		objs = new Object[size];
		this.size = 0;
	}
	
	//  
	public void ensureCapacity(){
		Object temp[] = objs;
		objs = new Object[objs.length + 10];
		for(int i = 0;i=index;i--){
			objs[i+1] = objs[i];
		}
		objs[index] = obj;
		size++;
	}
	//  
	public void remove(int index){
		for(int i = index;i iterator(){
		return new MyIterator(size,objs);
	}
}
package MYArrayList;
/**
 * 
 * @author zz384dian
 * @time 2018-2-15
 * @content Iterator   
 * @param 
 */
public class MyIterator {

	private Integer size;
	private Object objs[];
	private Integer current;
	
	public MyIterator(int size, Object objs[]){
		this.size = size;
		this.objs = objs;
		current = -1;
	}
	public E hasNext(){
		return (E)objs[current];
	}
	
	public boolean Next(){
		current++;
		if(current < size){
			return true;
		}
		return false;
	}
}
package MYArrayList;
/**
 * 
 * @author zz384dian
 * @time 2018-2-15
 * @content Student 
 */
public class Student {
	
	private String name;
	private Integer age;
	
	public Student() {
		super();
	}

	public Student(String name, Integer age) {
		super();
		this.name = name;
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return "Student [name=" + name + ", age=" + age + "]";
	}

}
package MYArrayList;
/**
 * 
 * @author zz384dian
 * @time 2018-2-15
 * @content     MyArrayList Test 
 */
public class Test {

	public static void main(String[] args) {
		// TODO Auto-genrated method stub
		MyArrayList al = new MyArrayList<>();
		al.add(new Student("zs",26));
		al.add(new Student("jyh",30));

		al.insert(0, new Student("k",26));
		//System.out.println(al.size());
		
		MyIterator iter = al.iterator();
		
		while(iter.Next()){
			System.out.println(iter.hasNext());
		}
		
		
	}

}