小编Arc*_*her的帖子

在Scala中,为什么Array("1")++"-3"输出Array [Any] = Array(1, - ,3)?

为什么在Scala 2.12.6中Array("1") ++ "-3"输出res1: Array[Any] = Array(1, -, 3)

我如何得到结果Array("1", "-3")

scala

7
推荐指数
2
解决办法
159
查看次数

是否可以使用quicksort计算计数反转次数?

我已经使用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)

python algorithm mergesort quicksort

3
推荐指数
1
解决办法
1429
查看次数

标签 统计

algorithm ×1

mergesort ×1

python ×1

quicksort ×1

scala ×1