int main()
{
int a[] = {1,2,3,4,5,6,7,8,9,10};
int len = sizeof(a)/sizeof(a[0]);
int *part1 = (int*)malloc(len/2);
int *part2 = (int*)malloc(len/2);
bool b = len%2?true:false;
for (int i = 0; i < len/2; i ++)
{
*(part1+i) = a[i];
if(b)
*(part2+i) = a[i+len/2+1];
else
*(part2+i) = a[i+len/2];
}
for (int i = 0; i < len/2; i ++)
{
a[i] = *(part2+i);
if(b)
a[i+len/2+1] = *(part1+i);
else
a[i+len/2] = *(part1+i);
}
return 0;
}
温馨提示:内容为网友见解,仅供参考