here is my Java programming homework question and I dont know howe to do it. I j
ID: 3564671 • Letter: H
Question
here is my Java programming homework question and I dont know howe to do it. I just spant almost a whole day for figure out this question then I decide ask some one...
Write a recursive methoed called countGreaterThan that counts the number of elements in a chain of linked nodes (that contain Integers) that are greater than a specified value.(you can reference/access the next and date fields of the Node class directly)
write a complete method with this method heaeder:
public int countGreaterThan(Node<Integer> headNode, int value)
for example, in the list 3>1>10>2>5, fi the method was invoked with value 3, the method would return the value2(there are two node that contain data greater than 3).
Explanation / Answer
public int countGreaterThan(Node<Integer> headNode, int value){
if (headNode==null){
return 0;
}
else if (headNode.date > value){
return 1 + countGreaterThan(headNode.next, value);
}
else{
return countGreaterThan(headNode.next, value);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.