Problem with dividing 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 ?
[471 byte] By [
qwedwea] at [2007-10-2 20:37:03]

You mean like in the middle of a quick sort routine?
Do you want to keep the elements in the same array that you started with (like you do in quick sort)?
Or are you actually trying to create a tree and need to copy the chunks out of one array, create two new arrays and move all the chunks into the new arrays, then immediately throw out the two new arrays that you just created, when you go break them down into chunks as well?
Are you allowed to move things around in the original array or are you supposed to leave them in the same order that you got them?
When you say "middle element" Do you mean the element that just happens to be sitting in the center slot of the first array or do you mean the "median" element, the element that would be sitting in the middle slot IF the array just happened to be sorted.
So - tell us what you are actually trying to do, and then maybe we can help you do it.
hello
Actually I'm trying to create a tree and need to copy the chunks of one array
into 2 newly created arrays.
I want to make median of the array elements as "root node"(no need to sort )
the array elements < median goes to new array (left)
& elements >= median goes to another new array (right).
But the process need to be done recursively i.e., whenever array is full,
it must split into 2 new arrays.
Any logic will be appreciated.
Thanks
Actually I'm implementing a k-dimensional tree (kd-tree).
Bcoz I need to perform some search operations on that algorithm.
No need to implement this algorithm, I can use some existing algorithm.
But I didnot find any algorithm on this tree.
So I'm trying to implement this algorithm by using arrays.
The question I asked you is a part of this algorithm.
Thanks