Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Download: http://solutionzip.com/downloads/count_list_elements-cpp/
- 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 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 above is to be included in a file named ListP.cpp
- The following code needs to go in ListP.cpp. The actual code of the function countValue() needs to be included:
- int countValue(list front ,const int item);
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[]){
- list front;
- int listCount;
- cout <> listCount;
- for (int i = 1; i <= listCount; i++)
- front.insert(i,rand()%5);
- cout << “Original List of Values: ” << endl;
- //writeLinkedList(front, ” “);
- cout << endl;
- for(int j=0;j<5;++j)
- cout << countValue (front,j) << endl;
- cout << endl;
- return 0;
- }
- Download: http://solutionzip.com/downloads/count_list_elements-cpp/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement