cours_progra/bac1/q2/algo/tp8/MyArrayList.java

36 lines
583 B
Java
Raw Normal View History

2023-05-05 13:02:58 +02:00
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();
}