Any improvements you can see? The 'inner loop' of the code is:
int getLongestPath(ArrayList<node> nodes, int nodeID, boolean[] visited){
visited[nodeID] = true;
int dist, max=0;
for(route neighbour: nodes.get(nodeID).neighbours){
if (!visited[neighbour.dest]){
dist = neighbour.cost + getLongestPath(nodes, neighbour.dest, visited);
if (dist > max){
max = dist;
}
}
}
visited[nodeID] = false;
return max;
}
The ArrayList of nodes could be changed to an array, but I don't imagine that'd be much faster (I've always heard that ArrayLists are just as fast as arrays, except for primitives).
*Edit: someone found a massive improvement, by replacing the node class with arrays, to simulate unboxing.
*Edit: someone found a massive improvement, by replacing the node class with arrays, to simulate unboxing.