sort function C++ segmentation fault

前端 未结 3 1631
面向向阳花
面向向阳花 2021-02-04 08:06

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

        
3条回答
  •  攒了一身酷
    2021-02-04 08:41

    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.

提交回复
热议问题