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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:49:12+00:00 2026-05-10T19:49:12+00:00

So my code is below. I’m not getting any errors and it places everything

  • 0

So my code is below. I’m not getting any errors and it places everything in the node just fine. But based on my debug statements Everytime anything is inserted it’s finding the root. I’m not sure if that is right. But according to output file for the assignment, my answers are different when it comes to the height of the tree, the traversals, and I just flat am still having troubles with my leaf count function. Another story though.

Based on the debug statements it looks like everything is going right where they should. But I figure I might need fresh eyes. I don’t see how my traversals could change at all since it is really only a matter of where I’m proccessing the node that should effect the Inorder, preorder, and postorder.

template <class T> void BT<T>::insert(const T& item)  {     Node<T>* newNode;     newNode = new Node<T>(item);     insert(root, newNode);  }   template <class T> void BT<T>::insert(struct Node<T> *&root, struct Node<T> *newNode)  {     if (root == NULL)        {           cout << 'Root Found' << newNode->data << endl;           root = newNode;        }     else         {            if (newNode->data < root->data)               {               insert(root->left, newNode);               cout << 'Inserting Left' << newNode-> data << endl;               }            else                {                insert(root->right, newNode);                cout << 'Inserting Right' << newNode->data << endl;                }         }  } 

My height function is as follows just in case my insert is actually fine.

template <class T> int BT<T>::height() const {    return height(root); }     template <class T>   int BT<T>::height(Node<T>* root) const    {    if (root == NULL)       return 0;    else        {       if (height(root->right) > height(root->left))          return 1 + height(root-> right);       return 1 + height(root->left);       }    } 
  • 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. 2026-05-10T19:49:12+00:00Added an answer on May 10, 2026 at 7:49 pm

    You need to change the wording of your debug statements

    Really it should read (not Root node)

     cout << 'Leaf Node Found' << newNode->data << endl; 

    It is only the root when it is first called after that any call with node->left or node->right makes it an intermediate node.

    To write height() I would do this:

    template <class T> int BT<T>::height(Node<T>* root) const {     if (root == NULL) {return 0;}      return 1 + max(height(root->left),height(root->right)); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You either use a collection and wrap it in Collections.unmodifiable*()… May 11, 2026 at 11:42 am
  • added an answer It doesn't matter what type your primary key is as… May 11, 2026 at 11:42 am
  • added an answer The primary place I use this trick is for creating… May 11, 2026 at 11:42 am

Related Questions

So my code is below. I'm not getting any errors and it places everything
The calculations in my code are well-tested, but because there is so much GUI
In my code behind I wire up my events like so: protected override void
So I'm refactoring my code to implement more OOP. I set up a class
So far I've been using public void run() {} methods to execute my code
Should I prepare my code for possible/predicted future changes so that it's easier to
I'm looking around for a Java code signing certificate so my Java applets don't
I want to see the stack trace in any function of my code, so
I´ve tweaked the VC++ settings so that all of my actual code will go
I've added the following code to my masterpage (Page_Load) so once a user logs

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.