My level of C++ knowledge:serious beginner.
Given the array:
int numbers[]={-2,-1,3,2,-8,6,-10,-12,5,1}
and the dimension as parameters to a function
i want to order the array: first negative then positive without
sorting them.
result example:-2,-1,-8,-10,-12,3,2,5,1
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void arrangeme(int v[], int n) {
int aux;
bool test;
do { test=false;
for (int i=0; i<n; i++)
if (v[i+1]<0) {
aux=v[i];
v[i]=v[i+1];
v[i+1]=aux;
test=true;
}
}
while(test==1);
}
|
How do i write a correct function to do that. I don't think it's too complicated for people to help me but it is to me.