I'm currently working on recursion in linked list and I have a question where I have to compare two numbers in a linked list and I have to do it recursively.
It return true if all the elements on the list are in an ascending order.
Here what I've done in my List :
public boolean ascending() {
if(this.first == null) return false;
return this.first.ascending();
}
Here what I've done in my Cells :
public boolean ascending() {
if(this.next != null) {
if(this.employee.getNumbers() < this.next.employee.getNumbers()) return true;
this.next.ascending();
} return false;
}
The problem is that my code return true for 100 < 200 but false for 100 < 200 < 300 and true for 100 < 200 < 100.
Any suggestion? Thank you in advance!