36 lines
583 B
Java
36 lines
583 B
Java
import java.util.Arrays;
|
|
|
|
public abstract class MyArrayList<T> {
|
|
protected T T1[], temp[];
|
|
protected int size;
|
|
|
|
public int size(){
|
|
return size;
|
|
}
|
|
|
|
public int physicalSize(){
|
|
return T1.length + temp.length + size * Integer.SIZE;
|
|
}
|
|
|
|
public T get(int i){
|
|
return T1[i];
|
|
}
|
|
|
|
public void add(T o){
|
|
makeSpaceIfNeeded();
|
|
T1[size++] = o;
|
|
}
|
|
|
|
public void add(int i, T o){
|
|
makeSpaceIfNeeded();
|
|
temp = Arrays.copyOfRange(T1, i, size-1);
|
|
T1[i] = o;
|
|
for(int j = 1; j <= temp.length; j++){
|
|
T1[j + i] = temp[i];
|
|
}
|
|
size++;
|
|
}
|
|
|
|
abstract void makeSpaceIfNeeded();
|
|
}
|