IN C++Write a recursive method insertLast(const ItemType& anEntry) to insert anEntry to the end of the Linked List.We can determine how many digits a positive integer has by repeatedly dividing by 10 (without keeping the remainder) until the number is less than 10, consisting of only 1 digit. We add 1 to this value for each time we divided by 10. Write a recursive function numOfDigits(int n) to return the number of digits of an integer n.

Respuesta :

tonb

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.

ACCESS MORE