Problem with diving an Array

hello everyone

I need some help to divide an array into 2 arrays with the middle element

of the array as the root node.

elements less than the root node should be in the left array &

greater than root node should be in the right array.

And after that if the left array is filled........ then have to repeat

the same process as above and so right array.

I'm not getting a way to do this.

...... Any ideas ?

[465 byte] By [qwedwea] at [2007-10-2 20:37:04]
# 1

You haven't said what problems you're having. So I am going to give you an idea for the first step of the process. To find the middle element of the array, you take the length and divide by 2. Round down if necessary. That's the index of the middle element. You should check in advance that the array has more than zero elements, otherwise the whole exercise is meaningless.

DrClapa at 2007-7-13 23:20:19 > top of Java-index,Core,Core APIs...
# 2

You need to look at your logic again.

You assume that;

- You have an odd number of elements

- half the elements in your array are less than the middle element and half are greater.

You appear to be attempting a merge sort using arrays. It is highly likely you can find 100s of examples of this with google. The follow gets 2Million+ hits

http://www.google.co.uk/search?q=merge+sort+using+array+example

Peter__Lawreya at 2007-7-13 23:20:19 > top of Java-index,Core,Core APIs...