Study the following method carefully which can be related to a certain class, decide what does it do?
question 7
-
Study the following method carefully which can be related to a certain class, decide what does it do?
public void Unknown(E item)
{
Node<E> node = new Node<E>(item);
Node<E> parent=null, current;
char d;
if(root == null)
root = node;
else
{
current = root;
while(current != null)
{
parent = current;
if (current.data < item)
{ current = current.right;
d=’r’; }
else
{ current = current.left;
d=’l’;
}
}
if(d==’l’)
parent.left = node;
else
parent.right = node;
}
}
a. Remove a node which its data is equal to item from a binary tree
b. Remove a node which its data is equal to item from a binary search tree
c. Insert a node in a binary search tree with item as its data
d. Insert a node in a binary tree with item as its data
Step by step
Solved in 2 steps