PRASHNIKAप्रश्निका
Back to the paper

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

Computer Science20262 marksShort answer
A linked list is formed from the objects of the class Node. The structure of the class Node is given below:
class Node
{
    char ch;
    Node next;
}
Write an Algorithm OR a Method to count and display the number of upper-case and lower-case characters. The method declaration is as follows:
void countCase(Node startptr)

Answer

Answer

AI
void countCase(Node startptr)
{
    int upper = 0, lower = 0;
    Node p = startptr;
    while (p != null)
    {
        if (Character.isUpperCase(p.ch))
            upper++;
        else if (Character.isLowerCase(p.ch))
            lower++;
        p = p.next;
    }
    System.out.println("Upper-case count: " + upper);
    System.out.println("Lower-case count: " + lower);
}
Explanation: A pointer p starts at startptr and traverses the linked list node by node until it reaches null (end of list). At each node, Character.isUpperCase()/isLowerCase() checks the character ch and increments the appropriate counter; the counts are displayed once the traversal is complete. Tested (run for real) on the list H-e-L-l-O: output was 'Upper-case count: 3' and 'Lower-case count: 2', which is correct (H, L, O are upper-case; e, l are lower-case).
Data structures

From ISC 2026 Improvement Computer Science Paper 1, question 11(i).