- <svg xmlns="http://www.w3.org/2000/svg" width="990" height="355" viewBox="0 0 990 355">
- <style>.t{font:16px sans-serif;fill:#1f2937}.s{font:13px sans-serif;fill:#475569}.n{fill:#fff;stroke:#2563eb;stroke-width:3}.x{fill:#fef3c7;stroke:#d97706;stroke-width:4}.e{stroke:#64748b;stroke-width:3}.a{stroke:#dc2626;stroke-width:4;fill:none}</style>
- <rect width="990" height="355" fill="#f8fafc"/><text x="28" y="33" class="t" font-weight="bold">Splay 的三种局部动作:旋转顺序由祖孙方向决定</text>
- <g transform="translate(35 75)"><text x="50" y="0" class="t">zig</text><line x1="65" y1="35" x2="65" y2="97" class="e"/><circle cx="65" cy="35" r="20" class="n"/><circle cx="65" cy="107" r="20" class="x"/><text x="65" y="41" class="t" text-anchor="middle">p</text><text x="65" y="113" class="t" text-anchor="middle">x</text><text x="8" y="155" class="s">父亲即 goal</text></g>
- <g transform="translate(330 75)"><text x="33" y="0" class="t">zig-zig</text><line x1="60" y1="35" x2="60" y2="96" class="e"/><line x1="60" y1="96" x2="60" y2="157" class="e"/><circle cx="60" cy="35" r="20" class="n"/><circle cx="60" cy="96" r="20" class="n"/><circle cx="60" cy="157" r="20" class="x"/><g class="t" text-anchor="middle"><text x="60" y="41">g</text><text x="60" y="102">p</text><text x="60" y="163">x</text></g><path d="M135 96 h60" class="a"/><path d="M195 96 l-12 -7 v14z" fill="#dc2626"/><text x="-7" y="210" class="s">同向:先 p,后 x</text></g>
- <g transform="translate(655 75)"><text x="33" y="0" class="t">zig-zag</text><line x1="70" y1="35" x2="35" y2="96" class="e"/><line x1="35" y1="96" x2="85" y2="157" class="e"/><circle cx="70" cy="35" r="20" class="n"/><circle cx="35" cy="96" r="20" class="n"/><circle cx="85" cy="157" r="20" class="x"/><g class="t" text-anchor="middle"><text x="70" y="41">g</text><text x="35" y="102">p</text><text x="85" y="163">x</text></g><path d="M145 96 h60" class="a"/><path d="M205 96 l-12 -7 v14z" fill="#dc2626"/><text x="-8" y="210" class="s">异向:x 连旋两次</text></g>
- <text x="35" y="323" class="s">每次 rotate 都保留中序;每次 splay 循环让 x 更靠近 goal。带 Lazy 时,旋前须从祖先到 x 依次 push。</text>
- </svg>
|