As form the lectures i know that bool return true or false based on condition mention
if the Condition is True then it will going to perform the swap operation if that i wrote return a < b
in my example my a and b is 50 30 , 50 < 30 which is false so in that case swappping is not going to perform . but it happened ? I am going to swap if the first element is greater than second
STL sort function with comparator
Swapping is done only when a<b.Observe your output. 50 and 30 are not being swapped. That is why 30 and 60 forms the 2nd output. Now 30 and 60 will be swapped…so the 3rd output is 30 and 40.
let I have 50 30 60 40 10
50 > 30 yes
30 50 60 40 10
50 > 60 no
30 50 60 40 10
60>40 yes
30 50 40 60 10
60 > 10
30 50 40 10 60 that all for the first pass and soon
I am assumming that comparison will this style the a and b index is incremented each time because the comparator in called inside the nested loop
so after 50 > 30 a>b then swap and the value of a and b in incremented and soon ?
Just data is being swapped. Nothing is being incremented.a and b are variables (temporary) and they will be different for each iteration. You do not require to consider index for a and b.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
@pratyush63
I am facing some issue need some guidelines. I am trying to find out the two return whose division is max x/y if it is greatest then i simply return the two numbers.
I want to know I am store the number to arrays then explicity return the no whose div is greatest. because when I am trying to do in if blocks each time the x and y is new. see the code