Sort function working

what is exactly happening in sort function when we give it a comparator function…

Comparator_in_STL
Check out this thread, feel free to ask if you still have any doubt.

Starting was good but were shifted towards priority queue I didn’t get that…

Comparators work alike throughout STL, this is a general overview of its working in case of sort and priority_queue. This pretty much summarizes everything regarding Comparators. You can skip the priority_queue part, it was explained distinctively for the asked doubt. If you understood how comparators work in sort, you are good to go. I am sure you will be able to derive it’s analogous working in other STL functions and containers yourself.