diff --git a/Data Structures/Scala/quick_sort.scala b/Data Structures/Scala/quick_sort.scala new file mode 100644 index 0000000..e5c8755 --- /dev/null +++ b/Data Structures/Scala/quick_sort.scala @@ -0,0 +1,8 @@ +def quickSort(arr: Array[Int]): Array[Int] = { + if (arr.length <= 1) arr + else { + val pivot = arr(arr.length / 2) + val (left, right) = arr.partition(_ < pivot) + quickSort(left) ++ arr.filter(_ == pivot) ++ quickSort(right) + } +}