Question: Here is the code for the countOccurrences method in the IntLinkedBag class: public int count 0 ccurrences ( int target ) { int answer; IntNode
Here is the code for the countOccurrences method in the IntLinkedBag class:
public int countccurrencesint target
int answer;
IntNode cursor;
answer ;
cursor IntNode. listSearchhead target;
while cursor null
Each time that cursor is not null, we have another occurrence of
target, so we add one to answer and then move cursor to the next
occurrence of the target.
answer;
cursor cursor ;
cursor IntNode. listSearchcursor target;
return answer;
When this method is called and the target is not in the bag, how many times will the while loop be executed?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
