def sort[T <% Ordered[T]] ( arr:Array[T] ) ( f: ( T,T ) =>Boolean ) = { for ( ( index, item ) <- ( 0 until arr.length ) zip arr ) { if ( index!=0 && f ( item,arr ( index-1 ) ) ) { var insertIndex=index-1 while ( insertIndex>=0 ) { if ( f ( item,arr ( insertIndex ) ) ) { arr ( insertIndex+1 ) =arr ( insertIndex ) arr ( insertIndex ) =item } insertIndex-=1 } } } }