public Node find(int x) { Node current = head; if (head.getData() == x) { return
ID: 3540642 • Letter: P
Question
public Node find(int x) {
Node current = head;
if (head.getData() == x) {
return current;
} else {
while (current != null) {
if (current.getData() == x) {
return current;
}// if
current = current.getNext();
}// while
}// if else
return null;
}// method find
please write the above method recusively or use recursion with the same task
Explanation / Answer
public Node find(int x)
{
Node current = head;
if (head.getData() == x)
{
return current;
}
else
{
if(current != null)
{
head=current.getNext();
find(x);
}
}
return null;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.