logo codesdope

Why did you use parent attribute in implemantation of code with c section in trees section of Data Structure?


Hi i just want to ask about small point of implementing tree with c.This code is very berief and i just wonder, why did you fill with null parent attribute in c section on new_tree_node function.Other implementation sections have this code like parent = null.(at the new_tree_node() function)

tree_node* new_tree_node(int data) {
  tree_node *n = malloc(sizeof(tree_node));
  n->data = data;
  n->right = NULL;
  n->left = NULL;
  n->parent = NULL; // Shoulden’t be?
  return n;

Another language

 public TreeNode(int data) {
    this.data = data;
    this.right = null;
    this.left = null;
    this.parent = null;



Write your answer

Welcome.please sign up.


Welcome.please login.