Sean O'Rourke
|
16
|
 |
|
03-04-2004 09:17 AM ET (US)
|
|
Shaniqua -- that is a correct example.
Omid -- remember that you can have a variable as part of a complex expression in prolog, so e.g. [1,A,2|B] means "a list consisting of '1', then something, then '2', then zero or more elements".
For part 3, it should be _easier_ to write BSTs in prolog ;). The general idea when doing data structures without assignment is to (conceptually) create a whole new copy with the necessary changes. In prolog, this looks like: modification(OldVersion, ..., NewVersion) :- ... i.e. a relation between the old and new versions of a data structure. Think of the recursive version of binary tree insertion, and try to formulate that as clauses of a relation.
autumn -- if it can't satisfy the relation, it will print out "no". If it can, it will print out a list of variable bindings, then a "?" to ask if you want more solutions. Just press enter. It should then print out "yes".
|