'(prolog)How to find the define child and parent relationship in a binary tree in prolog?

For example:

for binary tree bt(left,root,left)

define a relationship rule:

relationship(bt,parent,child) to find the child of the parent or the parent of child in bt.

eg:

-? relationship(bt(nil,4,5),4,child)

4 is the parent. so, the child is 5.

How to define the rules of this relationship in prolog?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source