Question

Implement the following method as a new static method for the IntNode class. (Use the usual...

Implement the following method as a new static method for the IntNode class. (Use the usual IntNode class with instance variables called data and link.) public static int count42s(IntNode head) // Precondition: head is the head reference of a linked list. // The list might be empty or it might be non-empty. // Postcondition: The return value is the number of occurrences // of 42 in the data field of a node on the linked list. // The list itself is unchanged.

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

public static int count42s(IntNode head) {

IntNode curr = head;


int count = 0;

while (curr != null) {

if (curr.data == 42)

++count;

curr = curr.link;

}

return count;


}



Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
Implement the following method as a new static method for the IntNode class. (Use the usual...
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