In this code, for vector size, n >=32767, it gives segmentation fault, but upto 32766, it runs fine. What could be the error? This is full code.
#include
This may be unrelated to your segmentation fault, but...
In C++, your "compare" predicate must be a strict weak ordering. In particular, "compare(X,X)"
must return "false" for any X. In your compare function, if both pairs are identical, you hit the test (p1.first <= p2.first)
, and return "true". Therefore, this "compare" predicate does not impose a strict weak ordering, and the result of passing it to "sort" is undefined.