Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, March 29, 2024

File: [Platon] / scripts / prolog / tree.prolog (download)

Revision 1.2, Mon May 2 10:56:21 2005 UTC (18 years, 11 months ago) by nepto


Changes since 1.1: +2 -2 lines

Fixed filename in the header.

%
% tree.prolog
%
% Developed by Ondrej Jombik <nepto@platon.sk>
% Copyright (c) 2005 Platon SDG, http://platon.sk/
% Licensed under terms of GNU General Public License.
% All rights reserved.
%
% Changelog:
% 2005-05-02 - created
%

% $Platon: scripts/prolog/tree.prolog,v 1.1 2005/05/02 10:55:41 nepto Exp $

%
% binary tree
%

bt(node(_,nil,nil)).
bt(node(_,Left,Right)):-bt(Left),bt(Right).

%
% binary search tree
%

lt(_,nil).
lt(X,node(Value,nil,nil)):-Value=<X.
lt(X,node(Value,Left,Right)):-Value=<X,lt(X,Left),lt(X,Right).

gt(_,nil).
gt(X,node(Value,nil,nil)):-Value>=X.
gt(X,node(Value,Left,Right)):-Value>=X,gt(X,Left),gt(X,Right).

bt_search(nil).
bt_search(node(Value,Left,Right)):-bt_search(Left),bt_search(Right),lt(Value,Left),gt(Value,Right).


Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top