add solutions for hw6:Base
This commit is contained in:
28
java/wspp/IntList.java
Normal file
28
java/wspp/IntList.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package wspp;
|
||||
|
||||
public class IntList {
|
||||
private int[] array;
|
||||
private int size;
|
||||
|
||||
public IntList() {
|
||||
array = new int[10];
|
||||
size = 0;
|
||||
}
|
||||
|
||||
public void add(int value) {
|
||||
if (size >= array.length) {
|
||||
int[] newArray = new int[array.length * 2];
|
||||
System.arraycopy(array, 0, newArray, 0, size);
|
||||
array = newArray;
|
||||
}
|
||||
array[size++] = value;
|
||||
}
|
||||
|
||||
public int get(int index) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user