Sort by Even and Odd numbers

前端 未结 6 1088
故里飘歌
故里飘歌 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:02

    If you look at a reference for std::sort you will see that the function it uses to compare should take two arguments that it should compare. So your code will not work at all.

    I recommend you instead iterate over the vector, sorting out even values into one temporary vector, and the odd values into another temporary vector. Then you clear the actual vector, and append the two temporary vectors in the order you like.

提交回复
热议问题