Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 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
Reply With Quote
  #2  
Old 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?
Reply With Quote
  #3  
Old 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
Reply With Quote
  #4  
Old 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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "JAVA- divide an array of integers into 2 parts"
Thread Thread Starter Forum Replies Last Post
Array of objects in java Ash maker Software Development 5 27-02-2010 02:05 AM
Help with two dimensional array java GlassFish Software Development 3 30-11-2009 01:57 PM
Array problems in java NetworkeR Software Development 2 06-11-2009 02:36 PM
Reading integers from a file into a character array afidelino Software Development 3 08-08-2009 11:32 AM
JAVA array Daren Software Development 2 06-03-2009 06:13 PM


All times are GMT +5.5. The time now is 07:27 AM.