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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:44:30+00:00 2026-05-21T15:44:30+00:00

Hey so I am attempting to write a BST but I am having a

  • 0

Hey so I am attempting to write a BST but I am having a lot of errors and I am pretty overwhelmed and lost on what to do. Can you guys take a look and point out anything that is off. The teacher wasn’t very useful at all at explaining anything.

header in the .h file

class Tree
{
public:
    bool insert(int k, string s);

private:
    struct Node
    {
        int key;
        string data;
        Node *left;
        Node *right;
    };
    Node* root;
    bool insert(Node *& root, int k, string s);
};

the .cpp file

bool Tree::insert(int k, string s)
{
    return insert(root, k, s);
}
bool Tree::insert (Node *& root, int k, string s)
{
    if (root == NULL){
        root = new Node;
        root->key = k;
        root->data = s;
        root->left = NULL;
        root->right = NULL;
    }
    else if (root == k)
        return false;
    else if (root->key < k)
        insert (root ->left, k);
    else
        insert (root -> right, k);
}
  • 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-21T15:44:31+00:00Added an answer on May 21, 2026 at 3:44 pm

    It appears that you have a lot of untested code. You will have to get the features working one at a time.

    Furthermore, I see at least one instance of duplicated effort already. The preOrder and postOrder methods should be slight variations of the same algorithm, yet one is loop-based and the other works by function recursion.

    Set these source files aside, create a new project, and copy-paste over one feature at a time. Test thoroughly before moving on to the next feature. If you reach a feature that might already be latent in the existing code, don’t copy-paste from the old code, but instead leverage the existing tested code.

    Edit

    That looks like it should work. Here are a couple stylistic criticisms, if you want them :v) .

    1. The Node structure should have its own constructor. Always provide a constructor to help guarantee that nothing can be in an invalid state.
    2. Likewise, something needs to set root to NULL when you create a new Tree.
    3. Changing the value of the root argument is not good style. At first glance, it looks like left and right never receive non-NULL values. Personally I favor a pointer-to-pointer here, but some might agree with your implementation instead.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey guys having this really simple problem but cant seem to figure out have
Hey guys Im attempting to sort a linked list and having trouble with this
Hey guys take a look at this program. /* The craps game, KN king
Hey guys I wanted to create a JScrollPane but it won't work... and I
hey guys Im building a script by which Im attempting to find specific links
Hey guys i've just recently been getting a hang of sockets but ran into
Hey guys, I am attempting to post and image-type post to Tumblr using someone's
Hey,...very simple question I usually write php but happen to be programming with ASP.NET
Hey everyone I'm attempting to take the value inputed in one of my forms,
hey guys was hoping you could help me out.. The task seems simple but

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.