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 6969161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:32:46+00:00 2026-05-27T16:32:46+00:00

So I was working on a Project for a computer science class in which

  • 0

So I was working on a Project for a computer science class in which we need to create a binary search tree and a corresponding index. We needed to use recursion for this project.

Here is my class implementation:

class Leaf;
struct indexEntries;
class BinarySearchTree{
    public:
        BinarySearchTree();
        ~BinarySearchTree();

        //Helper Functions for recursive calls
        std::string search(std::string);
        void BuildTree(std::string);
        void inOrderPrint();

    private:
        //Recursive Functions
        void BuildTreeR(int start, int end, Leaf * r);
        void inOrderPrint(Leaf * start);
        Leaf * search(std::string inquiry, Leaf * start);
        void DeallocateTree(Leaf * start);

        //Data members
        Leaf * root;
        std::vector<indexEntries> BSTindex;     
};


class Leaf{
    public:
        Leaf(){
            indexID = "";
            AccNum = "";
            left = NULL;
            right = NULL;
        };
        void set_index(std::string input)      {indexID = input;};
        void set_AccNum(std::string input)     {AccNum = input;};
        void set_left(Leaf* newLeft)   {left = newLeft;};
        void set_right(Leaf* newRight) {right = newRight;};
        std::string get_index()    {return indexID;};
        std::string get_AccNum()   {return AccNum;};
        Leaf * get_left()  {return left;};
        Leaf * get_right() {return right;};

    private:
        std::string indexID;
        std::string AccNum;
        Leaf * left;
        Leaf * right;
};

And when I try to pass Leaf * BinarySearchTree::root to the function void BinarySearchTree::BuildTreeR(int, int, Leaf*) the Leaf that the root is pointing to goes unchanged.

Here is my BuildTreeR() function:

void BinarySearchTree::BuildTreeR(int start, int end, Leaf * parent){
    int mid = (start+end)/2;
    if(parent == NULL){
        parent = new Leaf;
        parent->set_index((BSTindex[mid]).indexID);
        std::string fullEntry = BSTindex[mid].dataBaseEntry;
        parent->set_AccNum(fullEntry.substr(4, 3));
    }

    if((mid-1)>start){
        BuildTreeR(start, mid-1, parent->get_left());
    }
     if((mid+1)<end){
        BuildTreeR(mid+1, end, parent->get_right());
    }
}

Using the debugger, I found that the leaf pointed to by Leaf * parent gets changed, but these changes are not carried over to Leaf * BinarySearchTree::root, which stops my program from working.

The debugger says that the value of the data I’m trying to change is

CXX0030: Error: expression cannot be evaluated  

Has anyone had this happen before/ know how to fix it?

  • 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-05-27T16:32:47+00:00Added an answer on May 27, 2026 at 4:32 pm

    Your analysis of the problem is exactly right: the pointer is passed by value, so any changes that the function makes to the value of parent are not visible to the caller.

    One way to fix the problem is by passing the parent pointer by reference:

    void BinarySearchTree::BuildTreeR(int start, int end, Leaf *& parent){
    

    (note the added &).

    This way any changes made to parent inside the function will automatically be visible to the caller.

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

Sidebar

Related Questions

I am currently working on my fourth year project (computer science) which involves the
I'm working on a project for my computer science class that basically uses an
I am working on a project for my computer security class and I have
I am currently working on a computer science project where I have to evaluate
I am Computer Science student and working on a project in java through netbeans
I am working a project where I need to generate a series of classes
I am working on project in Linux which involves 1) Static Lib in C++
I am working on a project which consist of a procedure of reading diagram
I am working on a project in which I have to develop bio-passwords based
I am working on an OpenGL project for a computer graphics course, and I

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.