#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");
}
C语言—数据集合
猜你喜欢
转载自blog.csdn.net/Long_UP/article/details/121766795
今日推荐
周排行