// Predecessor return the biggest newKey, which newKey < key
Predecessor return the biggest newKey, which newKey < key
// Predecessor return the biggest newKey which newKey < key
func (rb RBTree) Predecessor(key int) (int, error) {
	node := rb.searchNode(key)
	if node == rb.nil() {
		return 0, fmt.Errorf("key %v does not exist", key)
	}
	if node.leftChild != rb.nil() {
		newNode := rb.maximumNode(node.leftChild)
		return newNode.key, nil
	}
	p := node.parent
	for p != rb.nil() {
		if node == p.rightChild {
			return p.key, nil
		}
		node = p
		p = node.parent
	}
	return 0, fmt.Errorf("key %v already the min key", key)
}
func ( rb RBTree ) Predecessor ( key int ) ( int , error ) { node := rb . searchNode ( key ) if node == rb . nil ( ) { return 0 , fmt . Errorf ( " " , key ) } if node . leftChild != rb . nil ( ) { newNode := rb . maximumNode ( node . leftChild ) return newNode . key , nil } p := node . parent for p != rb . nil ( ) { if node == p . rightChild { return p . key , nil } node = p p = node . parent } return 0 , fmt . Errorf ( " " , key ) }
Predecessor return the biggest newKey, which newKey < key
Predecessor return the biggest newKey which newKey < key