I've been given a task to implement a graph in java. It will eventually be used to test search methods (breadth first, depth first and iterative deepening). The three classes to be made have to implement three corresponding interfaces:
public interface Node {
public Node createNode(String name, int ID, float weight);
public Node[] getNeighbours();
public Edge[] getEdges();
public void addEdge(Edge e);
public void removeEdge(Edge e);
public String getName();
public int getID();
public float getWeight();
public String toString();
public interface Edge {
public Edge createEdge(String name, int ID, float weight);
public Node getStartNode();
public void setStartNode(Node n);
public Node getEndNode();
public void setEndNode(Node n);
public String getName();
public int getID();
public float getWeight();
public String toString();
public interface Graph {
public Graph createGraph(String name, int ID, Node[] nodes, Edge[] edges, Node root);
public String getName();
public Edge[] getEdges();
public void addEdge(Edge e);
public Edge getEdge(String name, int ID);
public void removeEdge(Edge e);
public Node[] getNodes();
public void addNode(Node n);
public Node getNode(String name, int ID);
public void removeNode(Node n);
public void setRoot(Node n);
public Node getRoot();
public boolean isTree(); <= optional!
public String toString();
The main method will be in the graph class.
I'm a bit confused as to why there is create methods for each class rather than constructors.
Also can anyone advise on whether I should store edges using an adjacency matrix or an adjancency list?
Any and all help will be greatly appreciated.
Thanks