solved Task 3

This commit is contained in:
schrom01 2022-11-01 12:30:08 +01:00
parent 1a8e8151a0
commit 812dd384ce
1 changed files with 15 additions and 6 deletions

View File

@ -1,15 +1,24 @@
package ch.zhaw.ads;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.*;
public class RouteServer implements CommandExecutor {
/**
build the graph given a text file with the topology
*/
public Graph<DijkstraNode> createGraph(String topo) throws Exception {
public Graph<DijkstraNode, Edge> createGraph(String topo) throws Exception {
Graph<DijkstraNode, Edge> graph = new AdjListGraph<>(DijkstraNode.class, Edge.class);
String[] lines = topo.split("\n");
for(String line : lines){
String[] strings = line.split(" ");
try {
graph.addEdge(strings[0], strings[1], Double.parseDouble(strings[2]));
graph.addEdge(strings[1], strings[0], Double.parseDouble(strings[2]));
} catch (Throwable e) {
e.printStackTrace();
}
}
return graph;
// TODO implement
}
@ -17,7 +26,7 @@ public class RouteServer implements CommandExecutor {
/**
apply the dijkstra algorithm
*/
public void dijkstraRoute(Graph<DijkstraNode> graph, String from, String to) {
public void dijkstraRoute(Graph<DijkstraNode, Edge> graph, String from, String to) {
// TODO implement
}