In the following program,
what does this mean left.parent = this; I know it says make parent of left child to be 'this' but what exactly is this. this refers to current instance method right? but can anyone explain a bit better.
public class TreeNode {
public int data;
public TreeNode left;
public TreeNode right;
public TreeNode root;
private int size = 0;
public TreeNode(int d) {
data = d;
size = 1;
}
public void setLeftChild(TreeNode left) {
this.left = left;
if (left != null) {
left.root= this;
}
}
Would the same function setLeftChild above be represented like the function below:
void setLeftChild(TreeNode node)
{
if(root == null)
{
this.root = node;
}
else
{
this.left = node;
}
}
- Is the implementation correct? first and 2nd?
- If not then what is wrong with the 2nd implementation? and vice versa
- What is the difference between first and 2nd implementation?


nodeis not necessarily the same asthisand it is theleft's root that is being set.