代码:
#include <iostream>
#include <string.h>
using namespace std;
void L(int A[],int n) {
int * B=new int [n] ();
int * C=new int [n] ();
int Q = 0, E = 0;
for (int i = 0; i <= n; i++) {
if (A[i] % 2 == 1) {
B[Q] = A[i]; Q++;
}
else {C[E] = A[i]; E++;
}
}
memcpy(A, B,Q*sizeof(int));
memcpy(A+Q, C,E*sizeof(int));
delete[]B;delete [] C;
}
int main() {
int A[9] = { 1,2,3,4,5,6,7,8,9 };
L(A,9);
for (int j = 0; j < 9; j++) {
cout << A[j] << endl;
}
}
运行结果:
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有