Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8387429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:12:29+00:00 2026-06-09T18:12:29+00:00

my knowledge is limited, writing in C++ for 2 months In this function string

  • 0

my knowledge is limited, writing in C++ for 2 months

In this function string code is recursively decrements chars until the base case "" is found. I want to prune some paths before the base case is found, and for some string code a path to the base case will not be found. For the prune I want to compare an attribute in the path with parameter int time. This searches a trie made of ‘nodeT’

struct charT {
char letter;
nodeT *next;
};

struct nodeT {
bool isOperation;
bool isCode; 
int time;
Vector<charT> alpha;
};

nodeT *root

usage:
string code = "12345";
int time = convertToEpoch(20120815); //my epoch function
containsCode(code, time)

bool containsCode(string code, int time)
{
    if(root == NULL) return false;
    else return containsCodeHelper(root, code, time);
}


bool containsCodeHelper(nodeT *w, string code, int time)
{
    if(code == "") //base case: all char found
        return w->isCode; 
    else {
        if (w->isOperation && w->time != time) return false; //case 2: time check OK <- at a midpoint in the path
        for(int i = 0; i < w->alpha.size(); i++) { //Loop through the leaf
            if (w->alpha[i].letter == code[0]) //case 3: leaf exists
                return containsCodeHelper(w->alpha[i].next, code.substr(1), time);
        }
    }
    return false; //if no path
}

This function worked well before adding the time check prune, it now loops, returns false if outside time but then starts again with the candidate string code from char location 0.

Questions: 1) Is a nested return false kicking the recursion back to the next call for loop, 2) should the time prune be placed in the for loop with a logical return false or return ‘path’, 3) is this more fundamentally messed-up and I need to learn a C++ concept <- please explain if yes.

Also, the posted function is a simplified version of the actual function – there is a modifier to time and a ‘step over’ path that I left out. In past question I found that these ‘addons’ distract from the question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:12:31+00:00Added an answer on June 9, 2026 at 6:12 pm

    after some reworking it now functions fine – possibly it always did; I changed to read attribute return w->isCode to return true, that seemed to be the biggest issue – I will debug the trie constructor and see if it is setting the attribute at the end of each path.

    boolcontainsCodeHelper(nodeT *w, string code, int time) 
    {
        if(code == "") //base case: all char found
            return true;
        else {
            if ( w->isOperation && (!((w->begin-wag) <= time && time <= (w->end+wag) ) && time != 9999 ) ) 
                return false; //case 2: time
            else {
                for(int i = 0; i < w->alpha.size(); i++) { //Loop through all of the children of the current node
                    if (w->alpha[i].letter == word[0])
                        return containsCodeHelper(w->alpha[i].next, word.substr(1), time, wag);
                    else if (word[0] == 'ž') //step over '0' all subnodes
                        if (containsCodeHelper(w->alpha[i].next, word.substr(1), time, wag)) 
                            return true;
                }
            }
        }
        return false; //if char is missing - meaning the exact code is not there - terminates garbage subnode paths
    }
    

    I don’t see any difference between having return false; at the end and leaving it out. Also still confused as why the special case needs if( bool fn()) return true; rather than just return ( bool fn()); i found that solution through trial and error with help from another stack overflow thread

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This sounds simple but my regex knowledge is limited. I need an expression to
I have a code. But, due to my limited knowledge. i researched and realised
My SQL knowledge is very limited, specially about SQLite, although I believe this is
I am not sure I am doing this right, with my limited knowledge of
We are transfering our code from C++ to C# and due to limited knowledge
I honestly have only started recently researching this so my knowledge is limited. I
I have limited knowledge of jQuery...I need help with this specific instance of a
I've reached the end of my limited knowledge with this problem. At the moment,
My PHP knowledge is limited and I am trying to implement http://www.tutorialchip.com/php-download-file-script/ this script
I don't know if this is possible or not, or if my limited knowledge

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.