package algorithm
object QuickSortApp {
def QuickSort(list: List[Int]): List[Int] = {
list match {
case Nil => Nil
case List() => List()
case head :: tail => // 使用head 作为算法中的基数
val (left, right) = tail.partition(_ < head)
QuickSort(left) ::: head :: QuickSort(right) // 递归调用,直到完成排序
}
}
def main(args: Array[String]): Unit = {
val lists: List[Int] = List(1, 10, 8, 100, -234, 0, 100)
for (ele <- lists) {
print(ele + "\t")
}
val list2 = QuickSort(lists)
println()
for (ele <- list2) {
print(ele + "\t")
}
}
}