Różnice
Różnice między wybraną wersją a wersją aktualną.
|
|
— |
pl:prolog:pllib:trees_heap_2 [2019/06/27 15:50] (aktualna) |
| ====== Trees heap 2 ====== |
| {{tag>trees heap}} |
| ===== Description ===== |
| Adjusting a binary tree to satisfy the heap property. |
| |
| **Source**: The Art of Prolog |
| ===== Download ===== |
| Program source code: {{trees_heap_2.pl}} |
| ===== Listing ===== |
| <code prolog> |
| /* |
| 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 |
| </code> |
| ===== Comments ===== |
| |