Whatever way it's possible, how can I do this? I need a method that modifies the actual list itself. I have tried doing this:
// Reverses this list.
public void reverse() {
for (int i = 0, j = size - 1; i < size && j >= 0; i++, j--)
set(i, get(j));
}
... but I failed. Halfway through it starts over and I'm just sucking. The output ends up being:
List: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
Reversed: [24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
How can I avoid this problem of repeating the numbers once it reaches the middle? Thanks.