Not all code paths return value

0

I did the program in c ++ and it compiled but when I tried to pass it to c # I throw the error with message: Not all the code paths return value

    public static bool backtracking(List<Nodo> arreglo, int n, int actual, LinkedList<Nodo> resultado, int inicio, int c)
    {
        resultado.AddLast(arreglo[actual]);
        colorcito[actual] = 1;
        c++;
        for (int i = 0; i <= n; i++)
        {
            if (colorcito[i] == 0 && relaciones[actual, i] != -1)
            {
                aristas[c] = relaciones[actual, i];
                if (c == n + 2 && i == inicio)
                {
                    return true;
                }
                backtracking(new List<Nodo>(arreglo), n, i, new LinkedList<Nodo>(resultado), inicio, c);
            }
        }
        c--;
        resultado.RemoveLast();
        colorcito[actual] = 0;
    }
    
asked by skar_543 27.09.2018 в 13:43
source

1 answer

0

Place return outside of for and if . It happens because, since it is inside a conditional, when the condition is not fulfilled, the function does not return any value, it should work in this way:

public static bool backtracking(List<Nodo> arreglo, int n, int actual, LinkedList<Nodo> resultado, int inicio, int c)
{
    bool result = false;
    resultado.AddLast(arreglo[actual]);
    colorcito[actual] = 1;
    c++;
    for (int i = 0; i <= n; i++)
    {
        if (colorcito[i] == 0 && relaciones[actual, i] != -1)
        {
            aristas[c] = relaciones[actual, i];
            if (c == n + 2 && i == inicio)
            {
                result = true;
            }
            backtracking(new List<Nodo>(arreglo), n, i, new LinkedList<Nodo>(resultado), inicio, c);
        }
    }
    c--;
    resultado.RemoveLast();
    colorcito[actual] = 0;
    return result;
}
    
answered by 27.09.2018 в 15:33