如何按monge随机顺序排序整数(0,1,2,3,4,5)数组(最奇数到最小奇数,然后最小甚至最大)像(5,3,1,0,2,4)。我无法解决这个问题。数组C++的唯一排序顺序
我用尽为止:
void mongeShuffle(int A[], int B[], int size)
{
int i = 0; // i is the index of the arr
while(i < size)
{
if(A[i] % 2 == 1)
{
B[i] = A[i];
i++;
}
else
{
B[i] = A[i -1];
i++;
}
}
}
你可以使用排序功能吗? – nhahtdh
不允许使用原始函数 – kxf951