Arrange array: negative then positive numbers

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.
Last edited on
There is standard algorithm std::stable_partition. You can use it or see its definition that to know how it works.:)
This isn't a C++ problem so much as a programming problem. A simple way would be a bubble sort in which the sorting criteria is simply positive numbers go on the right of negative numbers.

Look at element zero and one.
If left is positive and right is negative, swap them.
Look at elements one and two and continue.
When finished, go back to the start.
Keep going until you get a sweep right through without swapping anything.
Last edited on
i'm learning c++ in school, so i can't use smth that the teacher didn't teach.
I know in words but C++ syntax no
No Sorting is specified in my problem.

Thank you Moschops. I have advanced with my function. Testing right now.
Last edited on
Topic archived. No new replies allowed.