- Implement a method countValue() that counts the number of times an item occurs in a linked list. Remember to use the STL <list>
- *
-
- int countValue(list<int> front ,const int item);
- Generate 20 random numbers in the range of 0 to 4, and insert each number in the linked list. Output the list by using a method which you would call writeLinkedList which you would add to the ListP.cpp.
In a loop, call the method countValue() , and display the number of occurrences of each value from 0 to 4 in the list.*
- The below code needs to go in ListP.cpp. It is missing the actual code of the functions countValue() and writeLinkedList():*
*#include <list>*
- int countValue(list<int> front ,const int item);*
- void writeLinkedList(list<int> front);*
- using namespace std;*
- int main(){*
- list<int> front;*
- int listCount;*
- cout << “Enter the size of the list: “;*
- cin >> listCount;*
- for (int i = 1; i <= listCount; i++)*
- front.push_back(rand()%5);*
- cout << “Original List of Values: ” << endl;*
- writeLinkedList(front);*
- cout << endl;*
- for(int j=0;j<5;++j)*
- cout << “j = ” << j << ” : ” << countValue (front,j) << endl;*
- cout << endl;*
- return 0;*
- }*
- I have about got this solved I need help with the writelinkedList part of it. Thanks for your help.*





