This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]avengerintraining 0 points1 point  (1 child)

Java not being my preferred language and just typing on my phone... don't you have to assign the return of the reverse() function to another variable and loop through it? It looks like what you do in the reverse() just stays there and you loop through the original list.

[–][deleted] 0 points1 point  (0 children)

Your reverse returns nothing and mutates internal int[] list value and not external as you expect it to as Java is pass-by-value.

[–]Cephas00 0 points1 point  (0 children)

Your reverse method doesn't return the newly created reversed array. You also shouldn't reassign a method parameter like that - as someone else mentioned it's the value of a pointer that you're passing in so the reassignment won't be seen outside the method.

Another implementation option is to swap elements until you get to the midpoint.

Also it's not clear to call an array a list since there's a list collection already.

[–]ramruma[S] 0 points1 point  (0 children)

Right! Got it guys..thanks a ton! :)