Question

Write a recursive method contains(int target, LLNode<Integer> list) that returns true if list contains target and...

Write a recursive method contains(int target, LLNode<Integer> list)
that returns true if list contains target and false otherwise. For our example
list contains(15, values) would return true while contains(10, values)
would return false.

(JAVA language)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//assuming LLNode structure is like
class LLNode<T>
{
   T data;
   LLNode next;
}
boolean contains(int target, LLNode<Integer> list)
{
   if(list==null)//means not found
   return false;
   if(list.data==target)//found
   return true;
   return contains(target,list.next);//moving to next node in list
  
}

Add a comment
Know the answer?
Add Answer to:
Write a recursive method contains(int target, LLNode<Integer> list) that returns true if list contains target and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT