Sort by Even and Odd numbers

前端 未结 6 1019
故里飘歌
故里飘歌 2021-01-20 16:45

I would like to know is it possible to sort number by even or odd using the std::sort function.

I have the following codes but i am not sure how to implement in the

6条回答
  •  走了就别回头了
    2021-01-20 17:04

    For this, you should use std::partition instead of std::sort

    vector c;
    std::partition(c.begin(),c.end(),isEven)
    

    With sorting, you typically want the sorting to be based on the relative order of any two elements. In this case, you just want to partition your input based on an inherent property of your elements. Both cases can be reduced to the other, but it is always a little easier to take the direct approach.

提交回复
热议问题