Created
April 3, 2019 20:32
-
-
Save EbbeVang/8bd3c9b440a83792e3cacc2294382435 to your computer and use it in GitHub Desktop.
graph testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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