Reputation: 29
if possible please post some sample codes. Because we have a project wherein we need to set up locations within a map, and connect those locations with a line. Other than we also need to have a starting and end point in which we need to find a path going from the designated starting to the end point.
Upvotes: 0
Views: 1383
Reputation: 1234
Please if you did not read about Dijkstra, its the first you have to do if you wanna find a method to get the best(the shortest) route between two nodes...
Upvotes: 0
Reputation: 10003
import java.util.*;
class Node {
Node(Object object) {
this.object=object;
}
Object object;
List<Node> children=new ArrayList<Node>();
public String toString() {
return object.toString();
}
static void traverse(Node node) {
System.out.println(node);
for(Node child:node.children)
traverse(child);
}
}
public class Main {
public static void main(String[] args) {
Node root=new Node("root");
root.children.add(new Node("child 1"));
root.children.add(new Node("child 2"));
Node.traverse(root);
}
}
Upvotes: 1