Question

Write C++ code to: A linked list version of any_different(), called like this: bool any_different() const...

Write C++ code to:

A linked list version of any_different(), called like this:

bool any_different() const


(3) A RECURSIVE list member function of integer_linked_list that returns true if all elements in the list are equal to a passed in value.

bool all_equal_to(int val) const. // calls helper
bool all_equal_to_helper(snode* no, int val) const. // recursive

e.g., if the list had 10-->20-->30-->40-->50-->nullptr
and was passed val=30, it would return false
but if the list had 20-->20-->20-->20-->20-->10,
and was passed val=40, it would return false,
bur if it was passed val=20, it would return true

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

A RECURSIVE list member function of integer_linked_list that returns true if all elements in the list are equal to a passed in value.
Here ,head is the first node of integer_linked_list

bool all_equal_to(int val) const{
   return all_equal_to_helper(head,val);
}
bool all_equal_to_helper(snode* no, int val) const{
   if(no == NULL)return true;
   if(no->data != val)return false;
   return all_equal_to_helper(no->next,val);
}

Add a comment
Know the answer?
Add Answer to:
Write C++ code to: A linked list version of any_different(), called like this: bool any_different() const...
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