I was wondering what I am doing wrong with my get method. I've done this before using loops but I cant seem to get the same using recursion. My size() method works with recursion but I am very confused with why I can't seem to get get() to work. Can somebody give me any pointers to whats wrong or if I am just mixing up the positions of the code.
public class Node {
public Node previous;
public Node next;
public int size() {
int count = 0;
if (next == null) {
count += 1;
}
if (next != null) {
count = 1 + next.size();
}
return count;
}
public Node get(int idx) {
int count = 0;
if (next != null) {
if (idx >= 0 && idx <= size()) {
if (count == idx) {
return next.previous;
}
count++;
}
//return get(idx);
}
return next.previous;
}