This repository acts as a personal archive for my solutions to EdX course *Data Structures and Software Design* from PennX.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
722 B

public class DirectedGraph extends Graph {
public DirectedGraph() {
super();
}
@Override
public boolean addEdge(Node source, Node destination) {
addNode(source); // only adds if node not already in graph.
addNode(destination);
boolean addEdgeSuccess = addEdgeFromTo(source, destination);
if (addEdgeSuccess) {
numEdges++;
}
return addEdgeSuccess;
}
@Override
public boolean removeEdge(Node source, Node destination) {
if (!containsNode(source) || !containsNode(destination)) {
return false;
}
boolean removeEdgeSuccess = removeEdgeFromTo(source, destination);
if (removeEdgeSuccess) {
numEdges--;
}
return removeEdgeSuccess;
}
}