I am trying to write a program that will find the path from the beginning to the finish.I understand the DFS scene,the thing is I don't know how to solve the part where, I store all my information in a 2 dimensional array.Ok lets say
I have a list of cities
start,city 2,city 3,city4,city 5,city 6,finish
And the problem gives me the connections:
start city 5
city 3 finish
city 4 city 2
city 5 city 3
city 2 city 3 and city 5
So I want the array to look like this:
from the start you can go to city 5
start -->city 5
city 5 -->city 3
city 4 --> city2
city 2 --> city 3 and city 5
city3 --> finish
My stack will stop when it will reach the finish example:
finish
city3
city 5
start
In case a city is connected with two other cities like the city 2.If the program take the wrong way it will simply .pop().
The only thing I don't know how to do is the array sorting...Help :P