0

I dont know the use of "?" and ":".

return value < current.value
                ? containsNodeRecursive(current.left, value)
                : containsNodeRecursive(current.right, value);

2 Answers2

0

Exactly equivalent to this:

if (value < current.value) {
    return containsNodeRecursive(current.left, value);
else {
    return containsNodeRecursive(current.right, value)
}

Just a more compact way of writing it. Usually used for short if/else conditions to not use five lines of code, but only one.

Ondra K.
  • 2,767
  • 4
  • 23
  • 39
  • 2
    Better not to answer such an obvious duplicate, but link to the original question, where the asker will find much more information. – Ole V.V. Apr 04 '19 at 10:13
0
return value < current.value
            ? containsNodeRecursive(current.left, value)
            : containsNodeRecursive(current.right, value);

equals

if (value < current.value)
    return containsNodeRecursive(current.left, value)
else
    return containsNodeRecursive(current.right, value);

that means

condition ? do if true : do if false

Nikolay Gonza
  • 603
  • 5
  • 18
  • Better not to answer such an obvious duplicate, but link to the original question, where the asker will find much more information. – Ole V.V. Apr 04 '19 at 10:15