rbt: fix preorder

This commit is contained in:
c9s 2021-06-07 02:03:51 +08:00
parent 7805dcd72e
commit 5d8f7b3ea6

View File

@ -389,7 +389,7 @@ func (tree *RBTree) Preorder(cb func(n *RBNode)) {
}
func (tree *RBTree) PreorderOf(current *RBNode, cb func(n *RBNode)) {
if current != tree.neel {
if current != tree.neel && current != nil {
cb(current)
tree.PreorderOf(current.Left, cb)
tree.PreorderOf(current.Right, cb)