Hi
I have implemented a graph traversal algorithm which finds a path between two nodes in the graph. The problem is that it only finds a path for some queries when I know that there is a path between every node
public List getDirectRoute(Node start, Node end)
{
//Uses Dijkstras
List<Node> vis = new LinkedList<Node>();
Map<Node,Node> prev = new HashMap<Node,Node>(); // Records the previous Node
List<Node> route = new LinkedList<Node>(); //Will hold the final route
Queue<Node> queue = new LinkedList<Node>(); // Used for the algorithm
Node current = start;
queue.add(current);
vis.add(current);
while(!queue.isEmpty())
{
current = queue.remove();
if(current.equals(end))
{
break;
}else
{
for(Node node : successors(current) )
{
if(node.equals(vertices.get(0)))
{
continue;
}
if(!vis.contains(node))
{
queue.add(node);
vis.add(node);
prev.put(node, current);
}
}
}
}
if (!current.equals(end))
{
System.out.println("No route available");
}
for(Node node = end; node != null; node = prev.get(node))
{
route.add(node);
}
return route;
}
Am I missing something in the algorithm? I have run the debugger and but I can't find the problem