How we Defined Compare Function

Sir,I cann’t understand the fomation of comparator function(like how are we deciding the sign while defining it)?
and how does it work…