I have this problem of connected stations
connected(ataba,naguib).
connected(naguib,sadat).
connected(sadat,opera).
connected(opera,dokki).
and i should show the full path taken by the metro, from a source station to a destination
path(ataba,dokki,Z).
Z = [[ataba, naguib], [naguib, sadat], [sadat, opera],
[opera, dokki]] .
i tried to do this :
addlast(X,[],[X]).
addlast(X,[H|T],[H,NewT]):-
addlast(X,T,NewT).
path(X,Y,L) :- connected(X,Y),addlast([X|Y],L,R).
path(X,Y,L):-
connected(X,Z),
addlast([X,Z],L,R),
path(Z,Y,R).
when i tried to trace i noticed i have a problem with the stopping condition , i dont know how to solve it ,any advice or insights would be very helpful.