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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:17:26+00:00 2026-06-15T00:17:26+00:00

I have this method to add a node in a binary tree and here

  • 0

I have this method to add a node in a binary tree and here in the example, I first add 4 which works right,then when I add 10 I got this :
enter image description here

It first detect top != NULL which is correct, because there is 4 and then recall the method with top->droite in parameters(which is top->right). when it doesn’t detect top as NULL and skip, its became what you see in the screen shot.As you can see the varibale is NULL.

What am I doing wrong?

  • 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-15T00:17:27+00:00Added an answer on June 15, 2026 at 12:17 am

    By looking at the rest of the debug information, we can see that the left and right pointers of the new node are 0xcdcdcdcd, which, as far as I know, is the standard value for uninitiated pointers for debug builds in Visual Studio.

    Your error is not initializing the pointers of the new node. Here is what is happening:

    At the beginning top is NULL, and you insert the node whose nbr is 4. The new top is a node whose nbr is 4, but with the two pointers pointing to essentially garbage.

    When you try to insert 10, it will correctly compare 10 with 4, and try to insert 10 at the right subtree of 4. This right subtree is not initialized, and hence the error.

    One way to fix it is to make your code like this:

    static void insertion(Noeud *&top, Noeud *newNoeud) {
       if (top == NULL) {
           top = newNoeud;
           top->droite = NULL;
           top->gauche = NULL;
       } else if (newNoeud->nbr < top->nbr)
           insertion(top->gauche, newNoeud);
       else
           insertion(top->droite, newNoeud);
    }
    

    Here is a complete example: http://ideone.com/5TDD49

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

Sidebar

Related Questions

I have this method which leaks ~ 6KB : + (EInspectorFacilityInfo*) newWithNode: (CXMLNode*) node
So, I have implemented this method to add a footer to my table view:
i have written a method in java like this public boolean ADD(String ID,String Name,String
I have this method which lets me translate the position of an object, animating
I have a method to add an XML node structure to the currently selected
I have this code: public void AddNode(string Node) { try { treeView.Nodes.Add(Node); treeView.Refresh(); }
First, I have already read C++ Binary Search Tree status access violation error with
I have a method GetSelectedServices() which returns Selected Nodes from a Tree List, Expecting
So I have a method in a reservation model called add_equip. This method does
I have this method to display the contact numbers in my inbox: public ArrayList<String>

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.