Answer:
#include <iostream>
#include <cstdlib>
int numOfDigits(int n) {
if (std::abs(n) <= 9) return 1;
return 1 + numOfDigits(n / 10);
}
int main()
{
int a[] = { 0, 1, -24, 3456, 12345 };
for (int n : a)
std::cout << n << " has " << numOfDigits(n) << " digits" << std::endl;
}
Explanation:
This is the answer to your second question.
The first question requires some clarification on how the linked list is defined.