64,701
社区成员
发帖
与我相关
我的任务
分享
_Nodeptr _Lbound(const _K& _Kv) const
{_Nodeptr _X = _Root();
_Nodeptr _Y = _Head;
while (_X != _Nil)
if (key_compare(_Key(_X), _Kv)) //就是operator<调用的地方
_X = _Right(_X); //往右边子树走
else
_Y = _X, _X = _Left(_X); //记录父节点,往左边子树走
return (_Y); }
iterator find(const _K& _Kv)
{iterator _P = lower_bound(_Kv); //这个_P就是_Lbound返回的_Y
return (_P == end()
|| key_compare(_Kv, _Key(_P._Mynode())) //把_P再和_Kv对调了比较一下
? end() : _P); }