#include
int Remove(int a[], int len);
void print_arr(int a[], int n);
int main(void)
{
int a[] = {1, 2, 3, 4, 5};
int l;
if (l = Remove(a, 5))
print_arr(a, l);
return 0;
}
int Remove(int a[], int len)
{
int i, j;
i
for (i = 0, j = 0; i < len; ++i)
if (a[i] % 2)
a[j++] = a[i];
return j;
}
void print_arr(int a[], int n)
{
int i;
for (i = 0; i < n; ++i)
printf("%d ", a[i]);
}这样更快啊,O(n),只需要从头到尾扫描一次就可以啦