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
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
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'
... ? ... : ...
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.