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

  1. public class DirectedGraph extends Graph {
  2. public DirectedGraph() {
  3. super();
  4. }
  5. @Override
  6. public boolean addEdge(Node source, Node destination) {
  7. addNode(source); // only adds if node not already in graph.
  8. addNode(destination);
  9. boolean addEdgeSuccess = addEdgeFromTo(source, destination);
  10. if (addEdgeSuccess) {
  11. numEdges++;
  12. }
  13. return addEdgeSuccess;
  14. }
  15. @Override
  16. public boolean removeEdge(Node source, Node destination) {
  17. if (!containsNode(source) || !containsNode(destination)) {
  18. return false;
  19. }
  20. boolean removeEdgeSuccess = removeEdgeFromTo(source, destination);
  21. if (removeEdgeSuccess) {
  22. numEdges--;
  23. }
  24. return removeEdgeSuccess;
  25. }
  26. }