sorting using recursion
Posted
by user310587
on Stack Overflow
See other posts from Stack Overflow
or by user310587
Published on 2010-04-27T01:02:58Z
Indexed on
2010/04/27
1:03 UTC
Read the original article
Hit count: 359
I have the following function to sort an array with even numbers in the front and odd numbers in the back. Is there a way to get it done without using any loops?
//front is 0, back =array.length-1;
arrangeArray (front, back);
public static void arrangeArray (int front, int back)
{
if (front != back || front<back)
{
while (numbers [front]%2 == 0)
front++;
while (numbers[back]%2!=0)
back--;
if (front < back)
{
int oddnum = numbers [front];
numbers[front]= numbers[back];
numbers[back]=oddnum;
arrangeArray (front+1, back-1);
}
}
}
© Stack Overflow or respective owner