#include <stdio.h>
/*数组A={9,-2,4,-1,6,7,-3},
调整后即为:{-2,-1,-3,9,4,6,7}
*/
int main()
{
int a[7]={9,-2,4,-1,6,7,-3};
int *p,*q;
int temp;
p = &a[0];
q = a + 6;
printf("\n未调整的数据集合\n");
while(p <= a + 6)
{
printf("%4d",*p);
p++;
}
p = a;
while(p <= q)
{
if(*p >= 0 && *q < 0)
{
temp = *p;
*p = *q;
*q = temp;
p++;
q--;
}
if(*p < 0)
p++;
if(*p >= 0 && *q >= 0)
q--;
}
printf("\n调整后的数据集合\n");
p = a;
while(p <= a + 6)
{
printf("%4d",*p);
p++;
}
printf("\n");
}
07-12
431
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)