C#C
C#2y ago
mrmiyagi

simple algorithm question

FUNCTION CountX(t: Tree; x: INTEGER): INTEGER
BEGIN
    IF t = NIL THEN
        CountX:= 0;
    ELSE IF t^.val = x THEN
        CountX:= 1;
    ELSE
        CountX:= CountX(t^.left; x) + CountX(t^.left; x);
END;


Quick question:

In this function lets say that the "else if" comes true in the first node. wouldnt it just skip the "else" and give out CountX = 1 ?
so in order to solve that, my recursive call should not be bound by that "else" and should be done anyway

(the code is pascal, but that shouldnt matter with this simple algorithm)
Was this page helpful?