TechArena Community JAVA- divide an array of integers into 2 parts

#1
18-03-2009
 Member Join Date: Feb 2009 Posts: 117
JAVA- divide an array of integers into 2 parts

I have an array of integers done it this way:

[1,0,2,0,3,0,4,0,5,1,6,0,7,0,8,0,9,0,10,0,11,0,12,0,13,0,14,1,15,0,16,0,17,1,18,0,19,0,20,0,21,0,22,0 ,23,0,24,0,25,0]

I would divide it into two arrays, on the one hand, less than 15 and the other the more than 15:
then one that goes from 1 to 17:

[1,0,2,0,3,0,4,0,5,1,6,0,7,0,8,0,9,0,10,0,11,0,12,0,13,0,14,1,15,0,16,0,17]

and another 17 to 25:
[17,1,18,0,19,0,20,0,21,0,22,0,23,0,24,0,25,0]

you have any idea about it?
thanks
#2
18-03-2009
 Member Join Date: Mar 2008 Posts: 227
Re: JAVA- divide an array of integers into 2 parts

As ever in the second array which should not be in very large number, all the numbers are interspersed with zero and one?
What you can not do?
#3
18-03-2009
 Member Join Date: Feb 2009 Posts: 117
Re: JAVA- divide an array of integers into 2 parts

Quote:
 represent the previous state .. is a bit difficult to explain
represent the previous state .. is a bit difficult to explain
#4
18-03-2009
 Member Join Date: Mar 2008 Posts: 227
Re: JAVA- divide an array of integers into 2 parts

Then the values are to be considered in pairs.
This is one possible solution:
• Create 2 arrays arr1 and arr2 of the same dimension of the original and keep two indices last1 and last2 indicating the position of the element respectively arr1 and arr2.
• Make a loop over all elements of the input and depending on the value enter in arr1 or arr2 appropriately increasing indices.
• After completing the cycle with last1 and revenues last2 the actual size of the array and shifts new dimension and you just recopy the array.

 Tags: