Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 11(i)

2 marks

Computer ScienceISC 2025 Computer Science Paper 1ProgramData structures

Write the program described below.

A linked list is formed from the objects of the class Cell. The class structure of the Cell is…

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)
Open in the Linked list visualiser

Answer

Answer

void lowercase(Cell str)
{
    int sum = 0;
    Cell temp = str;
    while (temp != null)
    {
        if (temp.m >= 'a' && temp.m <= 'z')
            sum = sum + (int) temp.m;
        temp = temp.right;
    }
    System.out.println("Sum of ASCII values of lowercase letters = " + sum);
}
The method traverses the linked list from the given node str to the end (right==null), adds the ASCII value of every lower-case character found (checked with the range 'a' to 'z') to sum, and finally prints the total.