I want to create a graph using Jgraph, and later use that graph to find the minimum spanning Tree.
How to create a graph using Jgraph?.
this is what I have implemented. Can you please tell me how to use kruskals algorithm from the package. I googled it, but couldn’t find any information on it.
import org.jgrapht.*;
import org.jgrapht.graph.*;
public class MyGraph {
UndirectedGraph<String, DefaultEdge> g = new SimpleGraph<String, DefaultEdge> (DefaultEdge.class);
public void addVertex(String name) {
// name=new String();
g.addVertex(name);
}
public void addEdge(String v1,String v2) {
g.addEdge(v1, v2);
}
public UndirectedGraph<String, DefaultEdge> getGraph() {
return g;
}
}
This the main class where user input such as no of edges and vertices is taken to create a graph to the Spanning tree of the graph created. Below is the complete answer to this question.
Below MyGraph class does all the work of creating the graph by taking edges and calculating the spanning tree. I have used jgrapht library to create graph