A linked list can be traversed recursively as well as iteratively. We want to co
ID: 3827693 • Letter: A
Question
A linked list can be traversed recursively as well as iteratively. We want to count the number of nodes in a linked list using recursion. Which of the following methods implements this concept? Select the one correct response. I int getCount (int count, LinkedNode current) {if (current == null) return count; else {count++; return getCount(count, current);}} II int getCount(int count, LinkedNode current) {if (current == null) return count; else {current = current.next; count++; return getCount(count, current);}} III int getCount(int count, LinkedNode current) {while(current != null) return count; else {do{count++; while(current != null);}} IV int getCount(int count, LinkedNode current) {if (current == null) return count; else {current = current.next; return count + getCount(count, current);}} Select one or more: IIIExplanation / Answer
Option D is correct.
else
{
corrent = current.next
return count + getCount(count,current)
}
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.