java - Find a path with BFS in a graph -


i want find path between 2 nodes in graph bfs. wrote function visit nodes in correct order (not sure if works, seems right me) need store the path (with list of edges makes path) , don't know how :\

can me ? in advance :)

you create array pof parents. if p[u] = v there edge v u in path source u. parent of source vertex null.

so when in current vertex v, before inserting adjacent vertex u in queue, make p[w] = v. when find destination vertex go backward in array p. starting destination vertex w, p[w] parent of w , p[p[w]] parent of parent of w , on.


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -