Skip to content

Instantly share code, notes, and snippets.

@joyofclojure
Created June 29, 2011 11:28
Show Gist options
  • Select an option

  • Save joyofclojure/1053676 to your computer and use it in GitHub Desktop.

Select an option

Save joyofclojure/1053676 to your computer and use it in GitHub Desktop.
split(leaf,_,leaf,leaf).
split(bst(L,A,R),X,L1,bst(L2,A,R)) :- A > X, split(L,X,L1,L2).
split(bst(L,A,R),X,bst(L,A,R1),R2) :- A < X, split(R,X,R1,R2).
insert(bst(L,A,R),X,bst(LX,A,R)) :- A > X, insert(L,X,LX).
insert(bst(L,A,R),X,bst(L,A,RX)) :- A < X, insert(R,X,RX).
insert(T,X,bst(L,X,R)) :- split(T,X,L,R).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment