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"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <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> </modules>
</component> </component>
</project> </project>

Wyświetl plik

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

Wyświetl plik

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