Fawzan
Fawzan

Reputation: 21

Replacement algorithms

for(k = i - 1; k >= 0; k--) {
    if(frame[j] == page[k])
        break;
    least = least < k ? least : k;        
} 

I don't understand this line " least = least < k ? least : k; "

can any one explain it for me

Upvotes: 0

Views: 66

Answers (2)

Mukit09
Mukit09

Reputation: 3399

least = least < k ? least : k;

It's equivalent to,

if(least < k)
    least = least;
else
    least = k;

Upvotes: 1

tckmn
tckmn

Reputation: 59283

It's equivalent to

least = Math.min(least, k);

or

if (!(least < k)) {
    least = k
}

See also: the Java documentation on the ternary operator (scroll to the "The Conditional Operators" section).

Upvotes: 6

Related Questions