0
pair<K,V> *RedBlackTree<K,V,Compare>::successor(K key) {
Node *found = findNode(key, root);
Node *p;
Node *ch;
Node *x;
Node *y;
if(found->right != sentinel)
return new pair<K,V>(found->right->key, found->right->value);
y = found->parent;
/* if it does not have a left child,
predecessor is its first left ancestor */
while(y != NULL && found == y->right) {
found = y;
y = y->parent;
}
return new pair<K,V>(y->key, y->value);
}
測試它看它是否工作? – 2011-04-14 20:26:54
也許這種問題更適合http://codereview.stackexchange.com/。 – musiKk 2011-04-14 20:29:01
你可能在Code Review有更好的運氣:http://codereview.stackexchange.com/ – IanGilham 2011-04-14 20:29:36