package data
import scala.collection.mutable.ListBuffer
object SelectSort {
def selectSort[T](comparator:(T,T)=>Boolean)(source:ListBuffer[T]):ListBuffer[T]={
for(i<-0 until source.length){
var min=source(i)
var index=i;
for(j<-i+1 until source.length){
if(comparator(min,source(j))){
min=source(j)
index=j
}
}
source(index)=source(i)
source(i)=min
}
source
}
def main(args: Array[String]): Unit = {
val source=ListBuffer(1,4,3,9,2,8,7,5,6)
println(selectSort[Int](_>_)(source).mkString(","));
}
}