I have a question regarding the removing part from a binary search tree function.
switch (childCount){
case 0: // It has no children then remove parent
if(current.value < parent.value){
parent.left = null;
} else{
parent.right = null;
}
break;
case 1: //it has 1 children, reassign to parent
if(current.value < parent.value){
parent.left = (current.left === null ? current.right : curent.left);
} else {
parent.right = (current.left === null ? current.right : current.left);
}
break;
I'm not really understanding case 1, and the values for parent.left AND parent.right. What does the (current.left === null ? current.right : curent.left) exactly mean? The syntax is throwing me off. I know it refers to a case that if it has one child, just reassign to the parent. But I'm still confused
Thanks,