object quickSort
{
def
main(args
: Array
[String
]): Unit
= {
val intArray
: Array
[Int
] = Array
.fill(1000)(util
.Random
.nextInt(1000))
val list
: List
[Int
] = intArray
.toList
val ints
: List
[Int
] = quickSort(list
)
for (elem
<- ints
) {
println(elem
)
}
}
def
quickSort(list
: List
[Int
]): List
[Int
] = list match
{
case Nil
=> Nil
case first
:: others
=>
val
(left
, right
) = others
.partition(_
< first
)
quickSort(left
) ::: first
:: quickSort(right
)
}
}
转载请注明原文地址: https://mac.8miu.com/read-498392.html