java - Recursion, Arraylist -


my homework create recursive static method receives arraylist of integers parameter. there elements have value of 0 , want switch 5, elements have value of 1 removed, , elements have value of 2 moved end. rest stays is.

i can think of ways without using recursion, how solve problem using recursion?

thank you.

your base case list of length 1, easy deal with.

a list of length 2, know last 1 element has been processed, harder deal with.

a list of length n, know last n-1 elements have been processed, should manageable.

so, can take list, pass list minus first element down next level of recursion, when processed sub-list back, deal 1 first element.

@steven schlansker right, though, not recursion-friendly task.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -