Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
link(1,2). link(2,3). link(3,4). link(3,6). link(6,7). link(6,5). % --------------------------------------------------------------------------- % % traverse( Origin, Destination, ReversePath ) % % traverse/3 traverses a directed graph defined by link(From,To). % The path taken is listed in reverse order: % [Destination, N3, N2, N1 , Origin] % % --------------------------------------------------------------------------- traverse(A,B,P) :- % to traverse a graph traverse(A,B, [], P) % - invoke the helper, seeding the visited list with the empty list . % % --------------------------------------------------------------------------- % traverse( Origin, Destination, Visited, ReversePath ) % --------------------------------------------------------------------------- traverse( A , B , V , [B,A|V] ) :- % Traversal of a graph from A to B, link(A,B) % - succeeds if there exists an edge between A and B. . % traverse( A , B , V , P ) :- % otherwise, we can get from A to B if... link(A,X) , % - an edge exists between A and some node X \+ member(X,V) , % - that we have not yet visited, traverse(X,B,[A|V],P) % - and we can get from X to B (adding A to the list of visited nodes . %