---
title: "scala之快速排序 "
author: "lw223"
date: "2009-09-08T15:44:21Z"
tags: []
slug: "scala"
draft: false
lastmod: "2009-09-08T15:44:21Z"
id: 464860
url: "https://fishlee.iteye.com/blog/464860"
---

网上非常流行的一个scala排序例子，我稍微改了下

```
package com.fish.test

import scala.compat.Platform.currentTime

object Sort extends Application{
  
  var array = Array(656,23,454,3,45,34,2234,324234) 
   
  val startTime = System.currentTimeMillis
  
  array = sort(array)
  array.foreach((array:Int)=>println(array))
  val endTime:Long = System.currentTimeMillis
  Console.println(endTime-startTime+"ms")
  
  def sort(st:Array[Int]):Array[Int]={
    if(st.length<=1)
      st
    else{
      val p = st(st.length/2)
      Array.concat(sort(st filter (p>)),
                   st filter (p==),
                   sort(st filter (p<)))
    }
  }
 
}
```