diff --git a/Sorting/quickSort/scala/QuickSort.scala b/Sorting/quickSort/scala/QuickSort.scala new file mode 100644 index 000000000..aad76d079 --- /dev/null +++ b/Sorting/quickSort/scala/QuickSort.scala @@ -0,0 +1,16 @@ +object QuickSort extends App { + def sort(list: List[Int]): List[Int] = { + list match { + case Nil => Nil + case oneElementList :: Nil => List(oneElementList) + case pivot :: tail => { + val (less, greater) = tail.partition(_ < pivot) + sort(less) ::: pivot :: sort(greater) + } + } + } + val originalList = List(10, 7, 8, 9, 1, 5) + val sortedList = sort(originalList) + println(s"originalList: ${originalList}") + println(s"sortedList: ${sortedList}") +}