小编Don*_*hoi的帖子

访问匿名命名空间内的变量(C++)

我有以下代码,但我不知道如何在此设置中访问匿名命名空间内的 x。请告诉我怎么做?

#include <iostream>

int x = 10;

namespace
{
    int x = 20;
}

int main(int x, char* y[])
{
    {
        int x = 30; // most recently defined
        std::cout << x << std::endl; // 30, local
        std::cout << ::x << std::endl; // 10, global
        // how can I access the x inside the anonymous namespace?
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ static anonymous unnamed-namespace

5
推荐指数
1
解决办法
1733
查看次数

我在Python代码中的合并排序返回[0]

我正在制作合并排序代码,但它没有排序.你看到它有什么问题吗?

def mergeSort(L):
if len(L) == 1:
    return L
else:
    # divide
    L1 = mergeSort(L[0:round(len(L)/2)])
    L2 = mergeSort(L[round(len(L)/2):len(L)])

    # merge
    i = 0
    j = 0
    K = []
    while i < len(L1) and j < len(L2):
        if L1[i] < L2[j]:
            K.append(L1[i])
            i=i+1
        else:
            K.append(L2[j])
            j=j+1
    return K
Run Code Online (Sandbox Code Playgroud)

输入:

L = [1,2,5,7,8,0,10,21,32,53,16,16,48,59,64,53,75,52,42,21,98,76??] 
Run Code Online (Sandbox Code Playgroud)

输出:

L = [0]
Run Code Online (Sandbox Code Playgroud)

python sorting merge mergesort python-3.x

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