- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
通过一些练习来磨练我的二叉树技能,我决定实现一个拉伸(stretch)树,如 Wikipedia: Splay tree 中所述。 .
我没有得到的一件事是关于插入的部分。
它说:
First, we search x in the splay tree. If x does not already exist, then we will not find it, but its parent node y. Second, we perform a splay operation on y which will move y to the root of the splay tree. Third, we insert the new node x as root in an appropriate way. In this way either y is left or right child of the new root x.
10
/ \
5 15
/ \ \
1 6 20
6
/ \
5 10
/ \
1 15
\
20
8 8
\ /
6 6
/ \ / \
5 10 5 10
/ \ / \
1 15 1 15
\ \
20 20
6 is not greater than 8 10 is not less than 8
8
/ \
6 10
/ \
5 15
/ \
1 20
10
/ \
5 15
/ \
11 20
13
/ \
10 15
/ / \
5 11 20 <-- 11, on the wrong side of 13
First, we search x in the splay tree. If x does not already exist, then we will not find it, but its parent node y. Then we add the new node as either a left or right child of the parent node. Thirdly, we perform a splay operation on the node we added which will move the new value to the root of the splay tree.
最佳答案
我不明白你描述的问题是如何发生的。如果要将 13 插入到这棵树中,首先必须找到它的位置:
10
/ \
5 15
/ \
11 20
11
/ \
10 15
/ \
5 20
13
/ \
11 15
/ \
10 20
/
5
First, we search x in the splay tree. If x does not already exist, then we will not find it, but its parent node y. Then we add the new node as either a left or right child of the parent node. Thirdly, we perform a splay operation on the node we added which will move the new value to the root of the splay tree.
关于language-agnostic - 伸展树(Splay Tree)插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2008630/
我是一名优秀的程序员,十分优秀!