From cb4e17d282dd3636d1690d559c6c673b7d8fcf92 Mon Sep 17 00:00:00 2001 From: "M. Olcay TERCANLI" Date: Fri, 26 Oct 2018 09:40:10 +0300 Subject: [PATCH] Create QuickSort.scala --- Sorting/quickSort/scala/QuickSort.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Sorting/quickSort/scala/QuickSort.scala 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}") +}