測驗 $\alpha-1$
此程式為 S-tree 的 implementation,一種 self-balancing BST,試著用 hint (類似 AVL tree 的 height) 估計子樹高度以平衡。
S-tree 在 插入節點 (st_insert) 後會對該節點做 st_update 以平衡(左旋或右旋)以及更新 hint 值 (max(left hint, right hint)+1)。只要該節點不為 root 且該節點的 hint 值和平衡前一樣,就會對該節點的 parent 繼續做 update。
移除節點 (st_remove) 則會依照要移除的節點有不同行為:
有 right child: 和 right child subtree 的 first node (successor) 交換 value 並移除,再對 successor 的 right child 做 update
沒有 right child,有 left child: 和 left child subtree 的 last node (predecessor) 交換 value 並移除,再對 predecessor 的 left child 做 update
都沒有: 直接移除並對其 parent 做 update