Skip to content

Instantly share code, notes, and snippets.

@EbbeVang
Created April 3, 2019 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EbbeVang/8bd3c9b440a83792e3cacc2294382435 to your computer and use it in GitHub Desktop.
Save EbbeVang/8bd3c9b440a83792e3cacc2294382435 to your computer and use it in GitHub Desktop.
graph testing
import graph.Graph;
public class TestGraph {
public static void main(String[] args) {
// create graph
Graph<String> graph = new Graph<String>();
graph.addVertex("Rønne");
graph.addVertex("Hasle");
graph.addVertex("Allinge");
graph.addVertex("Aakirkeby");
graph.addVertex("Gudhjem");
graph.addEdge("Rønne", "Aakirkeby", 15);
graph.addEdge("Aakirkeby", "Gudhjem", 18);
graph.addEdge("Rønne", "Hasle", 10);
graph.addEdge("Hasle", "Allinge", 13);
graph.addEdge("Allinge", "Gudhjem", 15);
System.out.println("Vertices: " + graph.getAllVertices());
System.out.println("Edges: " + graph.getAllEdges());
System.out.println("Rønne and Gudhjem are connected: " + graph.isAdjecentVertices("Rønne", "Gudjhem"));
System.out.println("Rønne and Aakirkeby are connected: " + graph.isAdjecentVertices("Rønne", "Aakirkeby"));
System.out.println("Remove Hasle");
graph.removeVertex("Hasle");
System.out.println("Vertices: " + graph.getAllVertices());
System.out.println("Edges: " + graph.getAllEdges());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment