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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:39:39+00:00 2026-06-09T16:39:39+00:00

This question is related to a Binary Search tree. Here is the definition of

  • 0

This question is related to a Binary Search tree. Here is the definition of a node that I am using

struct _Node
{
    _Node *Parent;
    int Data;
    _Node *Left;
    _Node *Right;
};

Now here is the definition of the function to add a node once a root is created

void AddNode(_Node *Incoming, _Node *currentNode)
{

            if(!currentNode)
            {
                currentNode = Incoming;
            }
            else if(currentNode->Data >= Incoming->Data)
            {
                Incoming->Parent = currentNode;
                AddNode(Incoming, currentNode->Left);
            }
            else if(currentNode->Data < Incoming->Data)
            {
                Incoming->Parent = currentNode;
                AddNode(Incoming, currentNode->Right);
            }

}

AddNode function is based on a recursive approach. Main code is

_Node *Root= new _Node;
Root->Data = 50;
Root->Parent = nullptr;
Root->Left = nullptr;
Root->Right = nullptr;


_Node *Node2 = new _Node;
Node2->Data = 25;
Node2->Parent = nullptr;
Node2->Left = nullptr;
Node2->Right = nullptr;
_Node *Node3 = new _Node;

   AddNode(Node2, Root);

Problem:
Once I come out of the add node function I find that Root node doesnot have a Left or Right Child set to Node2. According to me as pointer to a node is passed each time I should have got the node added to the Root correctly. this is not happening. Can you please help me out here to understand what mistake I am making?

  • 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-09T16:39:40+00:00Added an answer on June 9, 2026 at 4:39 pm

    Try

    AddNode(Incoming, currentNode->Left);
    

    instead of

    AddNode(Incoming, Incoming->Left);
    

    Same for Right.

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

Sidebar

Related Questions

This question is related to this post : int to binary python I have
This question is related to another question I wrote: Trouble using DOTNET from PHP.
This question is related to the one I asked here . I'm trying to
This question is related to this SO post Rather than using a recursive CTE
This question is related somewhat to the one i asked HERE . Now, i
This question is geared towards MySQL, since that is what I'm using -- but
This problem is related to This question I asked yesterday. Now it seems that
This guy makes the extraordinary claim that binary search (in a C compiler) is
Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,
This question is related to another question, where I wanted to define a custom

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.