ltVal = node.left != null ? node.left.height : 0;
I think this is written in Java, can anyone explain what this means? Can't understand this shorthand notation
ltVal = node.left != null ? node.left.height : 0;
I think this is written in Java, can anyone explain what this means? Can't understand this shorthand notation
It is called ternary operator and it is only operator that takes 3
operands. In better sense, it is conditional operator that represent shorter format
General Syntax :
boolean expression ? value1 : value2
your example:
ltVal = node.left != null ? node.left.height : 0;
as same as
if( node.left != null)
itVal = node.left.height
else
itval = 0;