jeudi 23 avril 2015

Tracing through a recursive function

For the following code segment, I am having trouble tracing through it (which I need to be able to do for my upcoming test.

public int question(int x, int y)
    if (x ==y)
        return 0;
        return question(x-1, y) + 1;

I am also confused as to what the + 1 is doing. What is 1 being added on to. I know the result is five, but I need to be able to better understand the concept. Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire