exampple:7, 3, 5, 4
-List the total count of odd values in the linked list(from example above: 3)
-List the nodes data value of odd integers (from example above: 5, 7, 3)
-List the total sum of odd integers (from example above: 15)
-List the smallest and the largest odd number in the linked list (from example above: smallest= 3, largest= 7).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void List::Count()
{
node * temp = head;
int even;
int acc;
while(temp != NULL && (temp->data % 2) == 0)
{
acc += *temp->*data;
temp = temp->next;
}
if (acc != 0)
{
even++;
}
cout << "There are " <<even<< " even nodes." << endl;
cout << "The added value is "<<acc<<".\n";
}
|
I think the code gives me back the added address of temp instead of the actual values in acc int.
I need help to list the odd values on the linked list.
the rest of my functions work properly, I was thinking of using a vector or maybe I should use an array to store the list of odds, but I am not sure, also I am lost in how to do the last question.
help would really be appreciated, thank you