I encountered a question about STL today, suspected is the bug of sort!

xiaoxiao2021-03-05  27

I wrote a console program with VC : I found that once the sort value is all the same, and the total amount is greater than sort_max, and I have a custom function object: True returns True when it is determined to be equal (==). It will result in sorting abnormal (pointer, dead cycle):

Abnormal is the pointer, why can it lead to a cross-world, see below

#include "stdafx.h" #include #include using namespace std;

Class Greater {public: greater () {} Bool Operator () (int x1, int x2) {assert (x1 == 12); // I have made it here that the purpose is to judge the array crosions, why can it lead to a cross-boundary, See below if (x1> x2) Return False;}};

INT Main (int Argc, char * argv []) {// uint arr [] = {12, 14, 31, 9, 6, 30, 11, 65, 30 //}; uint arr [] = {12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12}; int nsize = sizeof (arr) / sizeof (uint); Greater GT Sort (Arr, Arr nsize, gt); for (int i = 0; i

Return 0;}

//// Sort is running here, there is a dead cycle in For (; _ p (* _ f, _piv); _ f), the reason is that the conditions I have started have all been satisfied (mainly _p (mainly _p) * _F, _piv) always return true), will lead to pointer offline, in addition, why always die cycle status, I am further studying ...

Template inline _ri _unguarded_partition (_ri _f, _ri _l, _ty _piv, _pr _p) {for (; _ f) {for (; _P (* _ f, _piv); _F); for (; _P (_piv, * --_1);); if (_l <= _f) return (_f); ore_swap;}}

转载请注明原文地址:https://www.9cbs.com/read-38271.html

New Post(0)