package data
import scala.collection.mutable.ListBuffer
object InsertSort {
def insertSort[T<%Ordered[T]](source:ListBuffer[T]):ListBuffer[T]={
for(i<-1 until source.length){
for(j<-(1 to i).reverse){
val current=source(j);
val prev=source(j-1);
if(current<prev){
source(j-1)=current;
source(j)=prev;
}
}
}
source
}
def main(args: Array[String]): Unit = {
val source=ListBuffer(3,5,4,9,1,8,7,6);
println(insertSort(source).mkString(","))
}
}