// 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 (rb RBTree) Successor(key int) (int, error) {
	node := rb.searchNode(key)
	if node == rb.nil() {
		return 0, fmt.Errorf("key %v does not exist", key)
	}
	if node.rightChild != rb.nil() {
		newNode := rb.minimumNode(node.rightChild)
		return newNode.key, nil
	}
	p := node.parent
	for p != rb.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 ( rb RBTree ) Successor ( key int ) ( int , error ) { node := rb . searchNode ( key ) if node == rb . nil ( ) { return 0 , fmt . Errorf ( " " , key ) } if node . rightChild != rb . nil ( ) { newNode := rb . minimumNode ( node . rightChild ) return newNode . key , nil } p := node . parent for p != rb . 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