Created
January 15, 2012 04:55
-
-
Save yesidays/1614401 to your computer and use it in GitHub Desktop.
code.jobs - Binary tree - 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
% Displaying a binary tree. | |
% show( Tree): display binary tree | |
show( Tree) :- | |
show2( Tree, 0). | |
% show2( Tree, Indent): display Tree indented by Indent | |
show2( nil, _). | |
show2( t( Left, X, Right), Indent) :- | |
Ind2 is Indent + 2, % Indentation of subtrees | |
show2( Right, Ind2), % Display right subtree | |
tab( Indent), write( X), nl, % Write root | |
show2( Left, Ind2). % Display left subtree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment