-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntVector.java
More file actions
31 lines (21 loc) · 709 Bytes
/
IntVector.java
File metadata and controls
31 lines (21 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class IntVector implements IntList{
final int CAPACITY=20;
int[] storageVector = new int[CAPACITY];
int lengthStorage=0;
@Override
public void add(int number) {
lengthStorage= storageVector.length;
if (lengthStorage==CAPACITY) {
int[] storagePlus =new int[CAPACITY + (CAPACITY / 2)];
//move elements to new largest array
for (int i=1; i < lengthStorage; i++) {
storagePlus[i] = storageVector[i];
}
//index-1 the last index
storagePlus[CAPACITY] =number;
}
} //end add
public int get (int id){
return id;
}
}