考虑我的树是这样的
5
/ \
3 7
/ \ / \
2 4 6 8
在那里,当我们搜索一个元素2
时,将执行 zigzig 操作,所以首先旋转parent and ancestor of 2
,然后旋转 a parent and 2
。
在同样的情况下,考虑到我们正在搜索4
,那个时候会执行 zigzag 操作。在那个第一个我们旋转4 and its parent
然后4 and its ancestor
将被旋转。
为什么我们这样做,在锯齿形中,为什么我们不旋转parent and ancestor
而不是searching node and parent
.
请解释一下??提前致谢。