Which of the following statement can switch p\'parent node with its left child o
ID: 3734326 • Letter: W
Question
Which of the following statement can switch p'parent node with its left child on a binary tree (assume p refers to an internal node with parent node and left child not null)?
A) temp=p.leftChild.getElement(); p.leftChild.setElement(p.getParent.getElement()); p.getParent.setElement(temp);
temp=p.leftChild; p.leftChild = p.getParent; p.getParent = temp;
p.leftChild = p.getParent; p.getParent = p.leftChild;
p.leftChild.setElement(p.getParent.getElement()); p.getParent.setElement(p.leftChild.getElement());
A) temp=p.leftChild.getElement(); p.leftChild.setElement(p.getParent.getElement()); p.getParent.setElement(temp);
B)temp=p.leftChild; p.leftChild = p.getParent; p.getParent = temp;
C)p.leftChild = p.getParent; p.getParent = p.leftChild;
D)p.leftChild.setElement(p.getParent.getElement()); p.getParent.setElement(p.leftChild.getElement());
Explanation / Answer
To switch p'parent node with its left child on a binary tree, following code will work correctly;
temp=p.leftChild;
p.leftChild = p.getParent;
p.getParent = temp;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.