object TestQuickSort2 { def main ( args : Array[String] ) : Unit = { var arrays = Array ( 123,343,5435,23,3213 ); println ( "排序前的结果" ); arrays.foreach ( println ) arrays = sort ( arrays ); println ( "排序后的结果" ); arrays.foreach ( println ) } def sort ( xs: Array[Int] ) :Array[Int] = { if ( xs.length <= 1 ) xs; else { val pivot = xs ( xs.length /2 ); Array.concat ( sort ( xs filter ( pivot > ) ), xs filter ( pivot == ), sort ( xs filter ( pivot < ) ) ) } } }
by: 发表于:2017-09-20 10:14:01 顶(0) | 踩(0) 回复
??
回复评论