why does this not work
public static ArrayList<Integer> reverseList(ArrayList<Integer> tList)
{
ArrayList<Integer> list = ListMethods.deepClone(tList);
if (list.size() <= 1)
{
return list;
}
else
{
list.add(list.size(), list.get(0));
list.remove(0);
reverseList(list);
}
return list;
}
Exception in thread "main" java.lang.StackOverflowError
at java.util.ArrayList.get(ArrayList.java:322)
at java.util.AbstractList$Itr.next(AbstractList.java:345)
at ListMethods.deepClone(ListMethods.java:29)
at ListMethods.reverseList(ListMethods.java:38)
at ListMethods.reverseList(ListMethods.java:48)
The list will never have a size smaller than itself. list.add(list.size(), list.get(0)); (+1) list.remove(0); (-1)
Unless deepCopy does something profound, this function will just clutter the stack with frames containing copies of the initial list until it overflows.
>>2
It's the error you get when you should have posted this shit at StackOverflow.
Name:
Anonymous2011-05-06 17:41
>>2
funny guy there. Believe me I'm tired of java at this point, I appreciate that it can make me money, has a nice library, and dev tools and that's about it.
Basically what's happening is the array is reversing but it just keeps reversing over and over because there is no way for me to shrink the list to satisfy the base case. Our piece of shit professor assigns 20 pages of java problems every week without even looking at what he's doing. He really sucks the fun out of this shit and makes me not care. There is a simple "do this instead" solution for this but since I have 19 more pages of this crap I never have time to sit down and think and enjoy the process. (our professor also "secretly" doesn't know java)
While we're learning discrete math and JVM assembly from other more reasonable professors. Literally 90% of my time goes to java and 8% discrete math 2% assembly.
Name:
Anonymous2011-05-06 17:47
>>5
Yeah because there is a ton of other great programming discussion here, you're the reason sussman thinks /prog/ is full of fags... also:
ENTERPRISE PROGRAMMER
CUDDER CUDDER CUDDER CAR CAR EVAL APPLY!!!!!
also frozenvoid buO00O0O02@faggot synACKsynACKsynACK ylpeR
>>6
It's because it never stops recursing and keeps loading up the stack. This btw is the 2nd recursion problem from the book.. which is fucking horrid since it involves issues not directly specific to recursion.
too much extra shit to keep in my head at once when I'm trying to learn something.
Name:
Anonymous2011-05-06 17:52
>>8
You're an idiot if you don't realize the SUSSMAN is Frozenvoid and love us dearly!