Rearrange even numbers in array to starting

Revision en1, by winter_s0ldier, 2021-06-08 09:46:37

I was trying to rearrange the array so that the even elements are at starting (order does not matter). I used lambda function in sort function but it is giving me segmentation error.

sort(all(arr), [](int p1, int p2){
        if(p1%2==0 && p2%2 == 0){
            
            return true;
        }
        else if(p1%2==0 && p2%2 != 0){
            
            return true;
        }
        return false;
    });

here all(x) = x.begin(), x.end() It is giving segmentation error for array size greater than 20. Can someone explain what is happening?

Tags #cpp17, #sorting, lambda expressions

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English winter_s0ldier 2021-06-08 09:46:37 633 Initial revision (published)