(int i, int goal)
| 68 | } |
| 69 | |
| 70 | public static void splay(int i, int goal) { |
| 71 | int f = father[i], g = father[f]; |
| 72 | while (f != goal) { |
| 73 | if (g != goal) { |
| 74 | if (lr(i) == lr(f)) { |
| 75 | rotate(f); |
| 76 | } else { |
| 77 | rotate(i); |
| 78 | } |
| 79 | } |
| 80 | rotate(i); |
| 81 | f = father[i]; |
| 82 | g = father[f]; |
| 83 | } |
| 84 | if (goal == 0) { |
| 85 | head = i; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // 整棵树上找到中序排名为rank的节点,返回节点编号 |
| 90 | // 这个方法不是题目要求的查询操作,作为内部方法使用 |