Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def r[A](l: List[A]): List[A] = {
- def _reverse(res: List[A], rem: List[A]): List[A] = rem match {
- case Nil => res
- case h :: tail => _reverse(h :: res, tail)
- }
- _reverse(Nil, l)
- }
- def sumuj (list1:List[Int],list2:List[Int]):List[Int]= {
- def sumuj_2(l1:List[Int],l2:List[Int],temp:List[Int]):List[Int]=
- (l1, l2) match {
- case (Nil,Nil) => r(temp)
- case (Nil,_) => sumuj_2(l1, l2.tail, l2.head::temp)
- case (_,Nil) => sumuj_2(l1.tail, l2, l1.head::temp)
- case (_,_) => sumuj_2(l1.tail, l2.tail, (l1.head + l2.head)::temp)
- }
- sumuj_2(list1,list2,Nil)
- }
- sumuj (List(1,2,3),List(4,5,6,7,8))
- sumuj (List(),List(4,5,6,7,8))
Advertisement
Add Comment
Please, Sign In to add comment