Advertisement
Guest User

Untitled

a guest
Apr 14th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.44 KB | None | 0 0
  1.     def insert(key: T) = {
  2.         def recInsert(tree: SplayTree[T]): Node[T] = {
  3.             tree match {
  4.                 case Node(l, v, r) if key < v => Node(recInsert(l), v, r)
  5.                 case Node(l, v, r) if key > v => Node(l, v, recInsert(r))
  6.                 case n: Node[T]               => n
  7.                 case _                        => Node(Leaf(), key, Leaf())
  8.             }
  9.         }
  10.         recInsert(this).splay(key)
  11.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement