java recursion test if arraylist are equal -
i have code make more efficient recursion. trouble don't know start. code compares 2 arraylists , b see if equal. assume sizes of both arrays equal.
the code is
public boolean isequal(a b) { boolean answer = false; if (lessthanorequalto(b) == true); (int = 0; < dlist.size(); i++) { if (dlist.get(i) == b.dlist.get(i)) answer = true; else answer = false; } return answer; }
i have written
public boolean isequalrecursion(a b) { if dlist.size() == 0; return false(); } else { }
i know stopping case 0 when size 0 nothing happens. have no idea write next
any appreciated
thanks
i think pretty start you. looks through elements, assuming array, , checks if equal in size.
public boolean isequal(arraylist<?> a, arraylist<?> b) { if (a.size() != b.size()) return false; (int = 0; < a.size(); i++) { if (!isequal((arraylist<?>)a.get(i), (arraylist<?>)b.get(i))) { return false; } } return true; }
now couple of things consider:
this assumes content of a(and b) must
arraylist
@ line(arraylist<?>)a.get(i)
if ourarraylist
contains else, integer?what if our array lists contain
null
item?what if pass in 2 null
arraylist
s? (or one?)
i'm not sure point of function lessthanorequalto(b)
part of question or did write down wrong?
also dlist
?
Comments
Post a Comment