Advertisement
Guest User

Untitled

a guest
May 28th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.93 KB | None | 0 0
  1. package application
  2.  
  3. import scala.collection.JavaConverters._
  4.  
  5.   object Sorting {
  6.     def MakeSort(mas: java.util.ArrayList[Integer]): java.util.List[Integer] = {
  7.       @annotation.tailrec
  8.       def Sort(notSortedMas: List[Integer], sortedMas: List[Integer]): List[Integer] = {
  9.         notSortedMas match {
  10.           case Nil => sortedMas
  11.           case x::rest =>
  12.             val (bigger, smaller) = sortedMas.partition(_ > x)
  13.             Sort(rest, bigger ::: x :: smaller)
  14.         }
  15.       }
  16.       Sort(mas.asScala.toList, List()).asJava
  17.     }
  18.   }
  19.  
  20. object Quicksort {
  21.   def MakeSort(mas: java.util.ArrayList[Integer]): java.util.List[Integer] = {
  22.     def Sort(mas: List[Integer]): List[Integer] = {
  23.       mas match {
  24.         case Nil => Nil
  25.         case x::tail =>
  26.           val (bigger, smaller) = tail partition (_ > x)
  27.           Sort(bigger) ++ (x :: Sort(smaller))
  28.       }
  29.     }
  30.     Sort(mas.asScala.toList).asJava
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement