Pabl0o0

Untitled

Oct 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. def r[A](l: List[A]): List[A] = {
  2. def _reverse(res: List[A], rem: List[A]): List[A] = rem match {
  3. case Nil => res
  4. case h :: tail => _reverse(h :: res, tail)
  5. }
  6. _reverse(Nil, l)
  7. }
  8.  
  9. def sumuj (list1:List[Int],list2:List[Int]):List[Int]= {
  10. def sumuj_2(l1:List[Int],l2:List[Int],temp:List[Int]):List[Int]=
  11. (l1, l2) match {
  12. case (Nil,Nil) => r(temp)
  13. case (Nil,_) => sumuj_2(l1, l2.tail, l2.head::temp)
  14. case (_,Nil) => sumuj_2(l1.tail, l2, l1.head::temp)
  15. case (_,_) => sumuj_2(l1.tail, l2.tail, (l1.head + l2.head)::temp)
  16. }
  17. sumuj_2(list1,list2,Nil)
  18. }
  19.  
  20. sumuj (List(1,2,3),List(4,5,6,7,8))
  21. sumuj (List(),List(4,5,6,7,8))
Advertisement
Add Comment
Please, Sign In to add comment