- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListForPoints.java
More file actions
Latest commit
44 lines (40 loc) · 812 Bytes
/
Copy pathArrayListForPoints.java
File metadata and controls
44 lines (40 loc) · 812 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
32
33
34
35
36
37
38
39
40
41
42
43
44
classArrayListForPoints{
Point[] elements;
intMAX_SIZE,size;
publicArrayListForPoints(){
elements = newPoint[384];
MAX_SIZE = 384;
size = 0;
}
publicArrayListForPoints(intMAX_SIZE){
elements = newPoint[MAX_SIZE];
this.MAX_SIZE = MAX_SIZE;
size = 0;
}
publicvoidadd(Pointt){
if (MAX_SIZE == size){ //COPY TO
Point[] array = newPoint[2*MAX_SIZE];
for (inti = 0;i<MAX_SIZE; i++){
array[i]=elements[i];
}
MAX_SIZE*=2;
elements=array;
}
elements[size++]=t;
}
publicPointget(intindex){
returnelements[index];
}
publicintsize(){
returnsize;
}
publicPoint[] toArray(){
returnelements;
}
publicPoint[] trimmedArray(){
Point[] result = newPoint[size];
for (inti = 0; i < size; i++)
result[i] = elements[i];
returnresult;
}
}