Page 1 of 1

remove node

Posted: Sat Dec 15, 2012 11:49 am
by omarasl
hello every body ,
Actually , I found functions which use to remove node from binary tree
these are the functions :

(defun BST-remove (B E)
"Remove E from BST B."
(if (BST-empty-p B)
B
(if (bin-tree-leaf-p B)
(BST-leaf-remove B E)
(BST-node-remove B E))))

(defun BST-leaf-remove (L E)
"Remove E from BST leaf L."
(if (= E (bin-tree-leaf-element L))
(make-empty-BST)
L))

(defun BST-node-remove (N E)
"Remove E from BST node N."
(let
((elmt (bin-tree-node-element N))
(left (bin-tree-node-left N))
(right (bin-tree-node-right N)))
(if (<= E elmt)
(if (bin-tree-leaf-p left)
(if (= E (bin-tree-leaf-element left))
right
N)
(make-bin-tree-node elmt (BST-node-remove left E) right))
(if (bin-tree-leaf-p right)
(if (= E (bin-tree-leaf-element right))
left
N)
(make-bin-tree-node elmt left (BST-node-remove right E))))))


when I try to use them , they do not work as the explanation .
I implement all the function inside
could somebody tell me how I can edit them to work
thank you very much