// Successor return the smallest newKey, which newKey > key
Successor return the smallest newKey, which newKey > key
// Successor return the smallest newKey which newKey > key
func (b BinarySearchTree) Successor(key int) (int, error) {
	node := b.searchNode(key)
	if node == nil {
		return 0, fmt.Errorf("key %v does not exist", key)
	}
	if node.rightChild != nil {
		newNode := minimumNode(node.rightChild)
		return newNode.key, nil
	}
	p := node.parent
	for p != nil {
		if node == p.leftChild {
			return p.key, nil
		}
		node = p
		p = node.parent
	}
	return 0, fmt.Errorf("key %v already the max key", key)
}
func ( b BinarySearchTree ) Successor ( key int ) ( int , error ) { node := b . searchNode ( key ) if node == nil { return 0 , fmt . Errorf ( " " , key ) } if node . rightChild != nil { newNode := minimumNode ( node . rightChild ) return newNode . key , nil } p := node . parent for p != nil { if node == p . leftChild { return p . key , nil } node = p p = node . parent } return 0 , fmt . Errorf ( " " , key ) }
Successor return the smallest newKey, which newKey > key
Successor return the smallest newKey which newKey > key