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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:22:08+00:00 2026-05-26T23:22:08+00:00

In a binary search tree that takes a simple object…..when creating the getter and

  • 0

In a binary search tree that takes a simple object…..when creating the getter and setter methods for the left, right, and parent. There are concerns about what is happening when a parent node is set. Code bellow…

The code:

 public void setParent(Person parent) {
  parent = new Person( parent.getName(), parent.getWeight());

The example code that inspired the code:

 public void setParent(Node parent) {
  this.parent = parent;
 }
  • 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-26T23:22:08+00:00Added an answer on May 26, 2026 at 11:22 pm

    You’re creating what is essentially a clone of the parent object. This is different from just saving the pointer to the parent object.

    Obviously, you’ll be taking more memory space by duplicating the parent object. More importantly, you’re not duplicating the parent’s references. So if you try to traverse the tree, go to a node’s parent, then try to visit its other children, you draw a bunch of null pointers.

    The this.parent is a reference to the current object’s parent pointer.

    It doesn’t actually mean that this is a parent. In fact, this.parent is used to distinguish the local parent pointer from the incoming parameter parent.

    class Person{
        Person parent; // <---- this is the "this.parent" attribute, and is initially undefined
        public void setParent(Person parent){ // <---- the "Person parent" on this line is an incoming parameter
            this.parent = parent; //<---- "this.parent" refers to the attribute, and "parent" refers to the parameter
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Alright, so I've been trying to implement a simple binary search tree that uses
I have a PHP script that builds a binary search tree over a rather
Given a simple binary tree, how can we prove that tree is a binary
In researching complexity for any algorithm that traverses a binary search tree, I see
I'm using a library that manipulates a binary search tree. In this library is
The problem: apply a binary search tree to a person object isntead of a
I know that SortedDictionary is a binary search tree (and it can almost do
I'm working on a simple app and the specs mandate that a binary search
So recently I have been working on phonebook project that uses Binary Search Tree.

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.