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:
pahimar 2013-05-30 15:42:41 -04:00
parent 6c8d0449ab
commit 603a88bb1c

View file

@ -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) {