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

  • Home
  • SEARCH
  • 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 3393370
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:02:34+00:00 2026-05-18T04:02:34+00:00

Solved – Problem with constructor Matthew Flaschen and Michael Burr pointed out the problem

  • 0

Solved – Problem with constructor

Matthew Flaschen and Michael Burr pointed out the problem of the overloaded constructor of Node(int) calling Node() which doesn’t work because…
Thanks guys!


I have built a program (I am debugging it) and have run into a weird problem… A `if` statement is not getting triggered when it should be… This is a school project where we must build an AVL Tree with at least one ‘optimizing’ feature.

I am sure and have tested that the `rdown` and `ldown` work (as the balancing factors) – the tree is not perfectly balanced. Rather it is based on the hight of the branches (i.e. – `balance()` should only return (1,0,-1) otherwise it is unbalanced.

I hope this is enough information to solve this weird problem… I have never ran into anything like this before with Microsoft Visual Studio 2010.

Node struct:

struct Node {
    int data;           // the data in the Node
    int rdown;          // the number of ellements below the node on the right side
    int ldown;          // the number of ellements below the node on the left side
    Node * parrent;     // the node's parrent
    Node * lchild;      // the nodes left child
    Node * rchild;      // the nodes right child

    Node () { rdown = 0, ldown = 0; data = 0; parrent = NULL; lchild = NULL; rchild = NULL; }
    Node (int dat) {rdown = 0, ldown = 0; parrent = NULL; lchild = NULL; rchild = NULL; data = dat; } 
    bool end() { if (lchild == NULL && rchild == NULL) return true;     // check if this node is the 'end of the line' - where it doesn't
                 return false; }                                        // have any children
    bool goodToAdd() { if (lchild == NULL || rchild == NULL) return true;   // make sture the current node has at least one spot to add
                       return false; }                                      // a new node to - either lchild or rchild must be NULL

    int balance() { return (ldown - rdown); }                           // get a balance number for the node
};

Search function that is causing the problems

Node * AVL_Tree::search(const Node * num) {
 Node * tmpNode = AVL_Tree::root;      // tmpNode is a place holder for the search
 for (int i = 1; true; i++) {     // increment int i to check for excess searching -> pervents endless loop
  if (tmpNode == NULL) //****** causing problems********  // the search has reached a dead end (the data is not contained) ==>  NULL
   return NULL;
  if (tmpNode->data == num->data)   // if the data of num is the same as tmpNode the data is contained ==>  Node *
   return tmpNode;
            // since the node has not been found yet move down the tree...
  if (tmpNode->data > num->data && tmpNode->lchild != NULL) // if the data is smaller than the tmpNode move to the lchild
   tmpNode = tmpNode->lchild;
  else if (tmpNode->rchild != NULL)    // since the node has been proven to not be = to the data to be searched for
   tmpNode = tmpNode->rchild;    // and it is not smaller... move to the right

  if (i > (root->ldown + 1) && i > (root->rdown + 1) ) {  // the while loop has searched suffecent time and has not ended
   string tmp = "the search incountered a critical error... aborting..."; // to prevent an endless loop the string error
   throw tmp;            // is thrown (should not happen) - indicates a broken tree
  }
 }
}

A screen shot of the first encounter with the for loop

alt text

A screen shot of the second encounter with the for loop

If you would note in the ‘Autos’ tab at the bottom that all the data and the node itself’s address is NULL – yet in the next screen shot it continues
alt text

The program continues!!! what?>!

I pushed F-10 (the ‘go to next command’ button) … and it jumps right over the statement? why?
alt text

  • 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-18T04:02:34+00:00Added an answer on May 18, 2026 at 4:02 am

    0xcdcdcdcd is not a NULL pointer – that value is used in the debug builds of MSVC for memory that has been allocated but not initialized.

    See When and why will an OS initialise memory to 0xCD, 0xDD, etc. on malloc/free/new/delete? for more details.

    The root of your problem might be in the constructor that takes an int parameter:

    Node (int dat) { Node(); data = dat; } 
    

    The Node(); statement ends up doing nothing. This constructor leaves most of the members of the structure uninitialized.

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

Sidebar

Related Questions

Problem solved: Thanks guys, see my answer below. I have a website running in
This problem has been solved thanks to your suggestions. See the bottom for details.
After having solved the problem of getting the editor to launch when there's a
SOLVED: Nevermind, the links were visited, and the border definition was missing for visited
Update: Solved, with code I got it working, see my answer below for the
Edit : Solved, there was a trigger with a loop on the table (read
I've actually solved this, but I'm posting it for posterity. I ran into a
I've just solved another *I-though-I-was-using-this-version-of-a-library-but-apparently-my-app-server-has-already-loaded-an-older-version-of-this-library-*issue (sigh). Does anybody know a good way to verify
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
Edit: I have solved this by myself. See my answer below I have set

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.