Advertisement
Guest User

linkedList drop

a guest
Apr 28th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.33 KB | None | 0 0
  1.   final def drop(n: Int): LinkedList[A] = {
  2.     val len = (this.length - n)
  3.    
  4.     @tailrec def inner(remaining: LinkedList[A]): LinkedList[A] =
  5.       remaining match {
  6.         case Nil() => Nil()
  7.         case Cons(h, t) => if (t.length > len) inner(t) else t
  8.     }
  9.     if (n > this.length) Nil()
  10.    
  11.     else inner(this)
  12.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement