为什么在Scala 2.12.6中Array("1") ++ "-3"输出res1: Array[Any] = Array(1, -, 3)?
我如何得到结果Array("1", "-3")?
我已经使用mergesort解决了这个问题,现在我在想是可以使用quicksort来计算数字吗?我也编写了快速排序,但我不知道如何计算.这是我的代码:
def Merge_and_Count(AL, AR):
count=0
i = 0
j = 0
A = []
for index in range(0, len(AL) + len(AR)):
if i<len(AL) and j<len(AR):
if AL[i] > AR[j]:
A.append(AR[j])
j = j + 1
count = count+len(AL) - i
else:
A.append(AL[i])
i = i + 1
elif i<len(AL):
A.append(AL[i])
i=i+1
elif j<len(AR):
A.append(AR[j])
j=j+1
return(count,A)
def Sort_and_Count(Arrays):
if len(Arrays)==1:
return (0,Arrays)
list1=Arrays[:len(Arrays) // 2]
list2=Arrays[len(Arrays) // 2:]
(LN,list1) = Sort_and_Count(list1)
(RN,list2) = Sort_and_Count(list2)
(M,Arrays)= Merge_and_Count(list1,list2)
return (LN + RN …Run Code Online (Sandbox Code Playgroud)