I am trying to split a list of integers into 2 lists of approximately equal length if my main list can't be evenly divided
My code so far is covering the "even split":
@Override
public Set<Bin> pack(int capacity, List<Integer> values) {
/**
* Divide the list into 2 equal parts if it can be Divided evenly
* Else, divide the List into 2 parts of roughly the same length
*/
int temp =values.size();
if(temp % 2 == 0)
{
ArrayList<Integer> list1 = new ArrayList<Integer>();
ArrayList<Integer> list2 = new ArrayList<Integer>();
for(int i = 0; i < temp / 2;i++)
{
list1.add(i);
}
for(int i = temp / 2; i < values.size();i++)
{
list1.add(i);
}
}else //divide the list into 2 approximately equal parts
{
}
return null;
}
How do I implement the rest of this method?