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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:33:32+00:00 2026-06-08T14:33:32+00:00

void BinarySearchTree::insert(int d) { tree_node* t = new tree_node; tree_node* parent; t->data = d;

  • 0
void BinarySearchTree::insert(int d)
{
    tree_node* t = new tree_node;
    tree_node* parent;
    t->data = d;
    t->left = NULL;
    t->right = NULL;
    parent = NULL;

    // is this a new tree?
    if(isEmpty()) root = t;
    else
    {
        //Note: ALL insertions are as leaf nodes
        tree_node* curr;
        curr = root;
        // Find the Node's parent
        while(curr)
        {
            parent = curr;
            if(t->data > curr->data) curr = curr->right;
            else curr = curr->left;
        }

        if(t->data < parent->data)
           parent->left = t;
        else
           parent->right = t;
    }
}

Questions:

  1. Why do I need to allocate memory for tree_node* t; using new but not for tree_node* parent;?

  2. What exactly is tree_node* what does it look like in memory and what does it do?

  3. Can someone explain to me the -> operator and how it works?

  • 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-08T14:33:35+00:00Added an answer on June 8, 2026 at 2:33 pm

    Why do I need to allocate memory for tree_node* t; using new but not for tree_node* parent;?

    You don’t need to, but it’s part of the logic. t represents the new node you’re inserting, so you need to create it first (which is done by the new). You don’t allocate memory for parent because it will refer to an already existing node:

     while(curr)
     {
        parent = curr;
        //...
    

    What exactly is tree_node* what does it look like in memory and what does it do?

    No way to tell (it should be defined somewhere), but it’s probably a structure like so:

    struct tree_node
    {
        tree_node* left;
        tree_node* right;
        int data;
    }
    

    Can someone explain to me the -> operator and how it works?

    It’s for accessing object members through a pointer. If you have Class* x, then x->a is equivalent to (*x).a.

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

Sidebar

Related Questions

void MainWindow::addRadioToUI() { int button_cunter=4; while(!database.isEmpty()) { button_cunter++; QPushButton *one = new QPushButton(Play: +name(get_r.getTrackId()));
void child(int pid){ printf(Child PID:%d\n,pid); exit(0); } void parent(int pid){ printf(Parent PID:%d\n,pid); exit(0); }
Assume that my delete tries to rebalance the tree inorder (left to right). I'm
void getThisAlert(String Title, Displayable txtagency2) { Alert error = new Alert(, Title, null, AlertType.INFO);
void test() { int buf[1000]; //populate buf foo(buf);//is this correct? Can we pass buf
void (int a[]) { a[5] = 3; // this is wrong? } Can I
void SomeClass::mySlot(MyClass *var){ ... } void SomeClass::SomeFunction(){ MyClass *myVar; QPushButton *button = new QPushButton(this);
void traverse(Node* root) { queue<Node*> q; Node* temp_node= root; while(temp_node) { cout<<temp_node->value<<endl; if(temp_node->left) q.push(temp_node->left);
void operator<< (const Integer& left, const Integer& right) { cout << \n: << right.i;
void ReadContent(string path) { Contract.Requires(path!=null); string contentofileasstring = filehelperobj.GetContent(path); if(String.IsNullOrEmpty(contentofileasstring )) { throw new

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.