.
This commit is contained in:
35
bac1/q2/algo/tp8/MyArrayList.java
Normal file
35
bac1/q2/algo/tp8/MyArrayList.java
Normal file
@ -0,0 +1,35 @@
|
||||
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();
|
||||
}
|
Reference in New Issue
Block a user