0

Can anyone tell me what this statement means? getHead is the first integer in an integer list:

        return (a.getHead() > m)? a.getHead():m;

Thank you

John Kugelman
  • 349,597
  • 67
  • 533
  • 578

2 Answers2

1

It's the same as the following:

if((a.getHead() > m)) 
     return a.getHead();
else
     return m;

This is the idea behind it:

if ' evaluate condition' ? 'what to do if condition is true' : 'what to do if condition is false'
A. Wolf
  • 1,309
  • 17
  • 39
0

... ? ... : ... is a ternary conditional.

The code you posted can be turned into

if (a.getHead() > m) {
    return a.getHead();
} else {
    return m;
}

That code will return the whichever is larger: the head of the list or m.

Michael Bianconi
  • 5,072
  • 1
  • 10
  • 25