Added skeleton code for adjacent node weightsa

pull/35/head
James Ball 2020-01-31 18:27:34 +00:00
rodzic 1af7df6a64
commit 41fc2a5380
4 zmienionych plików z 7 dodań i 4 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/oscilloscope-experiments.iml" filepath="$PROJECT_DIR$/.idea/oscilloscope-experiments.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/oscilloscope-renderer.iml" filepath="$PROJECT_DIR$/.idea/oscilloscope-renderer.iml" />
</modules>
</component>
</project>

Wyświetl plik

@ -26,8 +26,8 @@ public class Graph {
Node nodeA = nodes.get(line.getA());
Node nodeB = nodes.get(line.getB());
nodeA.addAdjacent(nodeB);
nodeB.addAdjacent(nodeA);
nodeA.addAdjacent(nodeB, line.length);
nodeB.addAdjacent(nodeA, line.length);
}
}
}

Wyświetl plik

@ -8,18 +8,21 @@ import java.util.List;
public class Node {
private Point location;
private List<Node> adjacentNodes;
private List<Double> adjacentWeights;
public Node(Point location) {
this.location = location;
this.adjacentNodes = new ArrayList<>();
this.adjacentWeights = new ArrayList<>();
}
public Point getLocation() {
return location;
}
public void addAdjacent(Node node) {
public void addAdjacent(Node node, double weight) {
adjacentNodes.add(node);
adjacentWeights.add(weight);
}
public int degree() {