Why it is showing error? Please tell me for that

Why it is showing error?
Please tell me for that.


I think my logic is correct.
Please tell What’s the issue don’t directly correct it in the code.

hi @cbcao263 i have made changes here https://ide.codingblocks.com/s/224932 and added comments as well so you’ll know exactly what I changed and the reason too. Let me know if you have any further doubts!

MamWhy you passed the pairs in the compare function. Why we can’t pass the vector in that function.

And One More Doubt, There you wrote incorrect syntax.
Why it was wrong like: -
v.push_back(make_pair(s,m))

@cbcao263 using make_pair wasn’t wrong.

you made a vector of size n. so now index 0 … n-1 are 0.
But now you are using push_back function so the elements get added beyond n-1th index. the size of your array will become 2n and first n elements will be 0, hence wrong logically.

In compare function, you can only compare two values right? like 2 int or 2 strings, and so on. How can you define a comparison for 2 containers? what does comparing 2 vector even mean? That doesnt make sense right? we call sort function on a container, like a vector or string, and we compare elements of that container. So if you are calling sort function for a vector of pairs, then pairs are passed as a parameter, Similarly if you call sort function on a string then you will compare 2 characters in the compare function.

I hope it is clear to you now.

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.