-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertex.java
35 lines (34 loc) · 904 Bytes
/
Vertex.java
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
import java.io.*;
class Vertex {
public int id;
public int x;
public int y;
public Edge[] edges;
public String toString() {
return x + ", "+ y;
}
public int edgeCount;
static int maxEdges = 10;
public Vertex(int id_, int x_, int y_) {
id = id_;
x = x_;
y = y_;
edgeCount = 0;
edges = new Edge[maxEdges]; //No vertex should have over 10 edges.
}
public void write(DataOutputStream out) throws IOException {
out.writeInt(id);
out.writeInt(x);
out.writeInt(y);
for (int i = 0; i < maxEdges; i++) {
if (edges[i] != null)
edges[i].write(out);
else
Edge.writeNull(out);
}
}
public void addEdge(int to, int weight) {
edges[edgeCount++] = new Edge(to, weight);
assert edgeCount <= maxEdges;
}
}