Graph Traversal Algorithm help....
I'm trying to do a Depth-First - Search algorithm... and I'm just about stuck in my implementation....
Code:
//traversal code given starting point
//and end point
public void traverse (String start, String end){
int i = node_index(start); //starting point
int j = node_index(end); //end point
int[]visted = new int [26]; //list of nodes we have already visited
int[]path = new int [26]; // the path we are taking
int path_pos = 0; //states the position we are in the path array
int visit_pos = 0; //states to position we are at our visited array
//algorithm
for (int count = 0; count <26; count++){
path[path_pos] = i;
visited[visit_pos] = i;
path_pos++;
visit_pos++;
//making sure that the end point is not viewable in the next move
for (int counter=0; counter < 26; counter++){
if (graph[i][counter]>0){
if (counter == j){
i = graph[i][counter];
counter = 0;
break;
}
}
}
//ending loop if we have found the end
if (i == j){
path[path_pos] = i;
visited[visit_pos] = i;
break;
}
//still working here
//searching for the first possible viewable node
for (int counter_2=0;counter_2<26; counter_2++){
if (graph[i][counter_2]>0){
for (int k =0;k<26;k++){
//testing if the node we are at has already been visited
if (visited[k] == counter_2){
break;
}
}
i = graph[i][counter_2];
counter_2=0;
break;
}
}
}
}
any ideas how to continue....
I'm trying to implement for the instance where i've reached a node where i've already visited and want to move back in my path to find a new path... help please
"And what's the real lesson? Don't leave things in the fridge"