java - select odd/even elements of array using recursion -



java - select odd/even elements of array using recursion -

am working on programming homework , bit lost. project select even/odd elements of listarray , store in array. not numbers in each element, elements if array had values "1,2,5,7,9" , returned elements give "1, 5, 9". have utilize recursion. able give me starting point or advice. though starting 2 elements , taking 2nd element , building that, don't know how add together on 2nd pass

public static arraylist<integer> even(arraylist<integer> list) arraylist<integer> evenlist = listmethods.deepclone(tlist);//make re-create of list if (evenlist.size()<=1) // list empty or has 1 element { // homecoming null;// homecoming list } if (evenlist.size()==2) { //return right element //call method 1 time again //add list }

this sounds similar homework completed, if (and you're in class!), i'll not tell utilize terminology haven't covered know can daunting trying find new practicals (beyond have do).

first, set exit condition. you've said, have create new arraylist out of existing one. going remove items existing arraylist, storing integers @ (or odd) indices, until list empty.

so exit status is:

if (evenlist empty) homecoming evenlist;

then, work way through steps. advise determining if array start has of odd number of steps, this:

if (evenlist has elements) int holderforintsatevenelements = lastly evenlist element

note start @ lastly element, when coming out of recursive method, lastly 1 added new arraylist, , it'll in numerical order. might find post interesting this: what boolean homecoming mean?

we want remove lastly element list , recursively phone call method again.

finally, when nail our exit status , start come out, want add together ints we've been storing them, e.g.:

evenlist.add(holderforintsatevenelements); homecoming evenlist;

that doesn't solve 1 problem, first element if list not have number of elements - however, i'll allow seek , solve that! that's mix of code , pseudo code , help on right track.

java recursion

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -