Queue q = new Queue();
Queue p = new Queue();
for (int i = 0; i < A.Length; i++)
{
if (A[i]%2==0)
{
p.Enqueue(A[i]);
}
else if (A[i]%2==1)
{
q.Enqueue(A[i]);
}
}
for (int i = 0; i < A.Length; i++)
{
foreach (var c in p)
{
A[i] = Convert.ToInt32(c);
i++;
}
foreach (var c in q)
{
A[i] = Convert.ToInt32(c);
i++;
}
}
return A;
用队列 ,将奇数、偶数分别存于队列中。再将原数组赋值。