Forgot to check to make sure that a weighted directed edge doesn't already exist between two nodes when attempting to add an edge
This commit is contained in:
parent
6c8d0449ab
commit
603a88bb1c
|
@ -47,7 +47,10 @@ public class WeightedDirectedGraph<T> implements Iterable<T> {
|
|||
throw new NoSuchElementException("Missing nodes from graph");
|
||||
}
|
||||
|
||||
graph.get(from).add(new WeightedEdge<T>(weight, to));
|
||||
// If a directed edge of the same weight doesn't already exist, add the new edge
|
||||
if (!edgeExists(from, to, weight)) {
|
||||
graph.get(from).add(new WeightedEdge<T>(weight, to));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean edgeExists(T from, T to) {
|
||||
|
|
Loading…
Reference in a new issue