Umm... You are increasing the value of i everytime you go through a loop.
while (l < left.size() && r < right.size())
{
if(right.get(r).compareTo(left.get(l)) > 0)
{
result.set(i,left.get(l));
l++;
}
else
{
result.add(i,right.get(r));
r++;
}
i++;
}
This while loop is half of the array.
while (l < left.size())
{
result.set(i,left.get(l));
l++;
i++;
}
And this while loop is the other half of the array.
At this point, i should be the full size of the array right? Then the below while loop while go over the size of your array.
while (r < right.size())
{
result.set(i,right.get(r));
r++;
i++;
}
wen_cai
Junior Poster in Training
64 posts since May 2012
Reputation Points: -3
Solved Threads: 17
Skill Endorsements: 2