[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Java
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 19
Thread images: 1
File: assn.png (18 KB, 391x468) Image search: [Google]
assn.png
18 KB, 391x468
Can anyone tell my why the recursion in this method isnt working, or how to fix it?
>>
Should you call depth-1?
>>
>>54372093
You're never decreasing depth, Einstein.
>>
>>54372126
>>54372122
Allready tried that, sadly doesnt work
>>
>>54372122
>>54372126
Also it might be worth noting that when the mark method is called, it removes the element equal to 'paper' from the ArrayList
>>
>>54372093
In what way is it not working?

Also, your function is just calling itself repeatedly with depth=0 until the itemList becomes empty. Is that actually what you want?
>>
>>54372256
Yeah that is what i want, and im getting a java.lang.StackOverflowError where the method calls itself.
>>
What is input?
What is EP?
What is itemList?

Yeah I can figure most of that out from the context probably, but if I'm supposed to help you with your shitty homework you might as well put the whole thing here.

If you're too afraid your teacher might find out then boil it down to a single question, not some lines and "it don't work lol"
>>
>>54372280
Okay that's fair, sorry.
EP is the class, itemList is an ArrayList of integers, and input loads ints into the ArrayList.
I suppose the main question is how can i get the for loop to repeat until itemList is empty, and i can't sort it, it has to be done unordered.
>>
u shouldn't try recursion outside of fp
stick with imperativism, cuck
>>
I dont even understand how your code is even recursive. Your "depth" parameter is kept the same, your not decrementing it or anything. Your basecase isnt even related to your "depth", but instead its an arraylist. Can you explain what your trying to do, like type it out in words
>>
>>54372304
>EP is the class
that's not helpful at all

like, what is pile.mark supposed to do? It seems like a crucial part of your algorithm, of which I'm still not sure what it's supposed to do.
>>
>>54372547
Okay so i need to input a line of values, say 1,0,2. These values get added to the arraylist.
Then i need to search through the array to find the value paper, adding a d to the string each time the arraylist element is not equal to paper, and an m if it is equal. If it is equal the element gets removed. i need to perform these steps until every element of the arraylist adds an m to the string.
this would make the output:
DMDMM
Hopefully that clears things up. Also i understand the recursion aspect will look very incorrect, but that is because i have been trying different things for hours now.
>>
>>54372567
I mentioned in an earlier comment that it removes the element that is equal to paper from the arraylist, sorry for not including it in the description.
>>
>>54372599
Then use an outer while and an inner for loop

here's some pseudo code
while (listNotEmpty) {
for each (element in list) {
if (element == paper) {
list.remove(element);
sort += 'M';
paper++;
break;
} else {
sort += 'D';
}
}
>>
>>54372642
whoops forgot a closing bracket
>>
>>54372646
Thank you, ill give it a go
>>
>>54372654
tell us if his solution worked OP, otherwise i can give you a slightly different one
>>
pastebin all classes used and ill help you out senpai
Thread replies: 19
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.