This question is about the linked list class: What are a and c? class List f cla
ID: 3678385 • Letter: T
Question
This question is about the linked list class:
What are a and c?
class List f class ListNode ( int value: ListNode nexti ListNode firsti /Return true if the value d is in the list and false " otherwise. The value d is in the list if d is equal * to the value field of any of the ListNodes in the * ist. 1 ns oun ish boolean findInList (int d) ( return findInListaux (d, stompo To e /* Return true if the value d is in the sub-list : beginning with the ListNode node. * private boolean findInListaux(int d, ListNode node) tExplanation / Answer
a) What is the base case of the recursion in findInListAux?
=> if there is no element in the list just return false.
Condition for no element in the list is (node == null)
so base case
if (node == null){
return false;
}
c) Write the body of the function findInListAux ?
private boolean findInListAux(int d, ListNode node){
if (node == null){
return false;
}
if (node.value == d){
return true;
}
return findInListAux(d,node.next);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.