Advertisements
Advertisements
Question
A linked list is formed from the objects of the class Cell. The class structure of the Cell is given below:
class Cell
{
char m;
Cell right;
}
Write an Algorithm OR a Method to print the sum of the ASCII values of the lower case alphabets present in the linked list.
The method declaration is as follows:
void lowercase(Cell str)
Long Answer
Advertisements
Solution
Algorithm to find the sum of ASCII values of lowercase letters in a linked list
- Begin from the head node of the linked list.
- Set a variable sum to 0.
- Repeat the following steps until the current node becomes null:
- Check whether the character stored in the current node lies between 'a' and 'z'.
- If it is a lowercase letter, add its ASCII value to sum.
- Move the pointer to the next node in the list.
- Once the traversal is complete, display the value of sum.
shaalaa.com
Is there an error in this question or solution?
2024-2025 (March) Official Board
