用数组写了一个线性表,但是没有测试,如果有问题,会在后面或回复指出。
public interface List<T> {
public boolean add(T newEntry);
public void add(int index, T newEntry);
public T remove(int index);
public void clear();
public T set(int index, T entry);
public T get(int index);
public boolean contains(T entry);
public int size();
public boolean isEmpty();
}
public class MyArrayList<T> implements List<T> {
private T[] array;
private int length; //存放数组中实际元素的个数
private int size; //存放数组的长度
private static final int MAX_SIZE = 50; //数组的默认长度
public MyArrayList() {
this(MAX_SIZE);