#include
#include
using namespace std;
class solution {
public:
vectorsortArrayByParity(vector& A)
{
int len = A.size();
if (len == 0 || len == 1)
return A;
for (int i = 0;i < len - 1;i++)
{
for (int j = 0;j < len - 1 - i;j++)
{
if (A[j] % 2 != 0 && A[j + 1] % 2 == 0)
swap(A[j], A[j + 1]);
}
}
return A;
}
};
int main()
{
int n = 0;
cout << "please Enter the lenth of array: ";
cin >> n;
vectorarr(n);
cout << "please Enter the elem of the array: ";
for (int &a : arr)
cin >> a;
solution s;
for (int a : s.sortArrayByParity(arr))
{
cout << a;
}
return 0;
}
1309

被折叠的 条评论
为什么被折叠?



