Skip to content

Instantly share code, notes, and snippets.

@yesidays
Created January 15, 2012 04:54
Show Gist options
  • Save yesidays/1614397 to your computer and use it in GitHub Desktop.
Save yesidays/1614397 to your computer and use it in GitHub Desktop.
code.jobs - Finding an item X - Prolog
% Finding an item X in a binary dictionary.
% in( X, Tree): X in binary dictionary Tree
in( X, t( _, X, _) ).
in( X, t( Left, Root, Right) ) :-
gt( Root, X), % Root greater than X
in( X, Left). % Search left subtree
in( X, t( Left, Root, Right) ) :-
gt( X, Root), % X greater than Root
in( X, Right). % Search right subtree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment