Implement a method countValue() that counts the number of times an item occurs in a linked list.
int countValue(RefList f, int item);
Generate 20 random numbers in the range of 0 to 4, and insert each number at the front of a linked list. Output the list by using a method which you would call writeLinkedList which you would add to the RefList.java (in page 414-421) program. In a loop, call the method countValue() , and display the number of occurrences of each value from 0 to 4 in the list.
* Declare an unsortedlinkedlist unlist.
* use a for loop in which you will do the following 20 times:
1. create a random number between 0 and 4
2. insert the number into the unlist
* print the elements in unlist.
* call the countValue method 5 times where each time you will send 2 parameters:
1. the unlist
2. the value of an int that is 0,1,2,3,4
* write the countValue method which accomplishes the followings:
1. it has 2 parameters:
o the unlist
o an int i
2. declare an int counter a.
3. make a list element out of the element i, say f2.
4. declare a for loop that will run 20 times in which you will do the following:
o get the first element from the unlist, say f1.
o make sure you compare f1 to f2.
o if they are equal increment the counter a.
5. return a.
6. done
write the countValue method which accomplishes the followings:
1. it has 2 parameters:
* the unlist
* an int v
2. declare an int counter a.
3. declare a for loop that will run 20 times in which you will do the following:
* get the first element from the unlist, say f1.
* make sure you compare f1 to v.
* if they are equal increment the counter a.
4. return a.
5. done
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|