© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
2 replies
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;
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)
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Simple question
C#CC# / help
3y ago
simple question [Answered]
C#CC# / help
4y ago
a simple question
C#CC# / help
4y ago