让你用编程代码表白,要怎么写呢?
2022-08-13 14:10
2022-08-13 14:10
别看
objectMainextendsApp{
varreverse_pairs = 0//逆序数
defmsort[T](cmp:(T, T) => Boolean)(l:List[T]):List[T] = {
defmerge(l1:List[T], l2:List[T]):List[T]=(l1, l2)match{
case(Nil, _) => l2
case(_, Nil) => l1
case(x::left1, y::left2) =>
if(cmp(x, y))
x::merge(left1, l2)
else{
reverse_pairs += l
1.length
y::merge(l1, left2)
}
}
valn = l.length / 2
if(n == 0)
return l
else{
val(l1, l2) = l.splitAt(n)
merge(msort(cmp)(l1), msort(cmp)(l2))
}
}
println(msort((x:Int, y:Int) => x
2022-08-13 16:23:25