Using Comparator in sort() function

Sir, I viewed the source code for sort() function.

Sorts the elements in the range @p [first , last) in ascending order, such that @p comp( (asterisk)(i+1),(asterisk)(i) ) is false for every iterator i in the range @p [first , last-1).

So, if I write the condition in “compare” function as

compare (int a, int b){

return a>b;

}

Basically, a = arr[i+1] and b = arr[i]

and whenever the condition a>b is false, it’ll swap the elements…?

That is, sorting is done to ensure that the condition inside the comparator stands false.

Is this reasoning correct or not…? If not, then please share the correct resoning.

hi @Lakshita2002 The algorithm used by sort() is IntroSort. Introsort being a hybrid sorting algorithm uses three sorting algorithm to minimise the running time; Quicksort, Heapsort and Insertion Sort.
The custom compare function basically tells the function if the elements receieved are in correct order or not. If the function returns true, it means they are ordered correctly, else they are swapped.

OK, I understand now. Thank you ma’am.