### 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

 ``1234567891011121314`` ``````void arrangeme(int v[], int n) { int aux; bool test; do { test=false; for (int i=0; i

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.