[SOLVED] All paths between 2 nodes in an unoriented graph | SoloLearn: Learn to code for FREE!

+1

[SOLVED] All paths between 2 nodes in an unoriented graph

Hi SoloLearn. I was wondering how can I print all the paths between 2 nodes in an unoriented graph. E.g: 5 8 1 4 1 3 3 5 4 5 2 4 1 2 4 2 3 4 start= 2 finish= 5 Result: 2 1 3 4 5 2 1 3 5 2 1 4 3 5 2 1 4 5 2 4 1 3 5 2 4 3 5 2 4 5 I am trying to use DFS, but if i keep a visited array, the DFS will find only one path. If I don't use visited, DFS will go in an infinite cycle. Thank you for your time:)

c++

7/20/2019 11:53:10 AM

Stefan Secrieru

3 Answers

New Answer

+9

https://stackoverflow.com/questions/31835814/display-all-possible-paths-between-the-2-nodes

+1

Thank you for your help, Zhenis Otarbay

+1

I solved this question, what I got wrong here was that after the DFS I forgot to mark a certain node as unvisited and to remove it from my path array. Farewell!