+ 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:)
3 Réponses
+ 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!