[scala]代码库
object MergeSort
{
def main ( args:Array[String] ) =
{
var list = List ( 3,5,6,1,1,4,7 );
sort ( list, ( x:int,y:int ) => ( x < y ) ).foreach ( println ( _ ) );/**
* MergeSort algorithm
* @Param def sort[T](args:List[T] , lessFunc:(T,T)=>Boolean):List[T]={
def merge( list1:List[T],list2:List[T]):List[T]={
if (list1.length <= 0) list2;
else if (list2.length <= 0 ) list1;
else if ( lessFunc(list1.head, list2.head) ) list1.head::merge(list1.tail,list2);
else list2.head::merge(list1,list2.tail);val medpos = args.length / 2;merge( args.take(medpos) , args.drop(medpos) );
}