Created
January 15, 2012 04:54
-
-
Save yesidays/1614397 to your computer and use it in GitHub Desktop.
code.jobs - Finding an item X - Prolog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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