Trees heap 2

Description

Adjusting a binary tree to satisfy the heap property.

Source: The Art of Prolog

Download

Program source code: trees_heap_2.pl

Listing

/*		
	substitute(X,Y,TreeX,TreeY) :- 
		The binary tree TreeY is the result of replacing all 
		occurrences of X in the binary tree TreeX by Y.
*/
 
	substitute(X,Y,void,void).
	substitute(X,Y,tree(Leaf,Left,Right),tree(Leaf1,Left1,Right1)) :-
		replace(X,Y,Leaf,Leaf1),
		substitute(X,Y,Left,Left1), 
		substitute(X,Y,Right,Right1).
 
	replace(X,Y,X,Y).
	replace(X,Y,Z,Z) :- X \== Z.
 
%	Program 3.26: Substituting for a term in a tree

Comments

pl/prolog/pllib/trees_heap_2.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0