cours_progra/bac1/q2/algo/tp8/MyArrayList.java
Debucquoy 4fd7542f03
.
2023-09-20 15:18:20 +02:00

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();
}