I am not able to understand that why are we checking this condition child!=par in the else if statement.
I think that child and parent nodes will always have different color because we have already colored parent node and passed different color for child node.
Please help