Question: Complete the implementation of a reference count-ing topological sort in the referenceCountSort class. The getSort() method should return a List , containing a topological sort

Complete the implementation of a reference count-ing topological sort in the referenceCountSort class. The getSort() method should return a List , containing a topological sort of the nodes in the graph.

//RefrenceCountSort.java//

package graph; import java.util.List; public class ReferenceCountSort extends AdjacencyGraph implements TopologicalSort { @Override public List getSort() throws GraphError { return null; } }

//GraphError//

package graph; /** * Superclass for graph specific errors * */ public class GraphError extends Exception { public GraphError() { super("Unspecified graph error"); } public GraphError(String message) { super(message); } }

//graph//

package graph; import java.util.Set; /** * An interface defining the functionality required of graphs. * * You should not modify this code. Instead implement graph(s) as separate classes. * */ public interface Graph { /** * Add a node to the graph. * * @param node the node to be added. * @throws GraphError if the node is already in the graph. */ void add(T node) throws GraphError; /** * Add an edge to the graph. * * @param start the start node of the edge to be added. * @param end the end node of the edge to be added. * @throws GraphError if the edge already exists, or if either start or end is not a node in the graph */ void add(T start, T end) throws GraphError; /** * Remove a node, and all edges leading to and from it, from the graph. * * @param node the node to be removed - all edges leaving the node, and all edges entering the node * will also be deleted. * @throws GraphError if the node does not exist. */ void remove(T node) throws GraphError; /** * Remove an edge from the graph. * * @param start the start node of the edge to be removed. * @param end the end node of the edge to be removed. * @throws GraphError if there is no such edge in this graph */ void remove(T start, T end) throws GraphError; /** * Check if the graph contains a given node. * * @param node the node to be checked. * @return (node is a node in the graph). */ boolean contains(T node); /** * Check if the graph contains a given edge between two nodes. * * @param start the start node of the edge to be checked. * @param end the end node of the edge to be checked. * @return (there is an edge from start to end in the graph). */ boolean contains(T start,T end); /** * Get all the nodes in the graph. * * @return a set containing all the nodes in this graph */ Set getNodes(); /** * Get the neighbours of a given node. * * @param node the node for which the neighbours should be found. * @return a set of the immediate successors of the node. * @throws GraphError if the node is not a node in the graph */ Set getNeighbours(T node) throws GraphError; /** * Get the number of nodes in the graph. * * @return the number of nodes currently in this graph */ int getNoOfNodes(); /** * Get the number of edges in the graph. * * @return the number of edges currently in this graph */ int getNoOfEdges(); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!