Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def insert(key: T) = {
- def recInsert(tree: SplayTree[T]): Node[T] = {
- tree match {
- case Node(l, v, r) if key < v => Node(recInsert(l), v, r)
- case Node(l, v, r) if key > v => Node(l, v, recInsert(r))
- case n: Node[T] => n
- case _ => Node(Leaf(), key, Leaf())
- }
- }
- recInsert(this).splay(key)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement