Hey guys. I hate to have to ask for help but I've run out of ideas. The program I'm trying to write is supposed to write a random list of numbers 0 - 4 and then count the occurrences of each number. The only thing I can't get to work is the countValue function.
//count the number of occurrences of each number in the linked list
Node* countValue(Node *pHead) //<------HERE'S THE PROBLEM
{
int count0;
int count1;
int count2;
int count3;
int count4;
Node *pNode;
for(pNode = pHead; pNode->next != NULL; pNode = pNode->next)
{
if(pNode->data == 0)
{
count0++;
}
if(pNode->data == 1)
{
count1++;
}
if(pNode->data == 2)
{
count2++;
}
if(pNode->data == 3)
{
count3++;
}
if(pNode->data == 4)
{
count4++;
}
}
cout << "0: " << count0 << endl;
cout << "1: " << count1 << endl;
cout << "2: " << count2 << endl;
cout << "3: " << count3 << endl;
cout << "4: " << count4 << endl;
return (pNode);
}