Advertisement
sheyshya1

dfs prologue

Dec 5th, 2021
1,327
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.53 KB | None | 0 1
  1. //dfs
  2.  
  3.  
  4. domains
  5. X=symbol
  6. Y=symbol*
  7. predicates
  8. child(X,X)
  9. childnode(X,X,Y)
  10. path(X,X,Y)
  11. clauses
  12. child(a,b). /*b is child of a*/
  13. child(a,c). /*c is child of a*/
  14. child(a,d). /*d is child of a*/
  15. child(b,e). /*b is child of b*/
  16. child(b,f). /*f is child of b*/
  17.  
  18. child(c,g). /*g is child of c*/
  19. path(A,G,[A|Z]):- /*to find the path from root to leaf*/
  20. childnode(A,G,Z).
  21. childnode(A,G,[G]):- /*to determine whether a node is child of other*/
  22. child(A,G).
  23. childnode(A,G,[X|L]):-
  24. child(A,X),
  25. childnode(X,G,L).
  26. goal:path(a,e,L).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement