-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBallPath.java
More file actions
67 lines (38 loc) · 943 Bytes
/
Copy pathBallPath.java
File metadata and controls
67 lines (38 loc) · 943 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import util.Point;
public class BallPath {
// supports basic functionalities of an array list
Point[] arr;
int color;
int num, cap;
public BallPath (int c, int cap) {
color = c;
this.cap = cap;
// initialise the Path
arr = new Point[cap];
for (int i = 0; i < cap; i = i + 1) arr[i] = new Point(-1, -1);
}
public void increaseCap() {
cap = 2 * (cap + 1);
Point[] temp = new Point[cap];
for (int i = 0; i < num; i = i + 1) temp[i] = arr[i];
for (int i = num; i < cap; i = i + 1) temp[i] = new Point(-1, -1);
arr = temp;
}
public void add(Point P) {
if (arr == null) return;
if (num >= cap) increaseCap();
arr[num] = P;
num = num + 1;
}
// getters
public int num() {
return num;
}
public int color() {
return color;
}
public Point get(int index) {
if (index > num - 1) return null;
return arr[index];
}
}