Choose the appropriate code that counts the number of non-zero(non-null) elements in the sparse array.

Choose the appropriate code that counts the number of non-zero(non-null) elements in the sparse array.
A.
Code:
public int count()
{
        int count = 0;
        for (List cur = this.next; (cur != null); cur = cur.next)
        {
            count++;
        }
        return count;
}
B.
Code:
public int count()
{
        int count = 0;
        for (List cur = this; (cur != null); cur = cur.next)
        {
            count++;
        }
        return count;
}
C.
Code:
public int count()
{
        int count = 1;
        for (List cur = this.next; (cur != null); cur = cur.next)
        {
            count++;
        }
        return count;
}
D.
Code:
public int count()
{
    int count = 1;
    for (List cur = this.next; (cur != null); cur = cur.next.next)
    {
        count++;
    }
    return count;
}
 

Tìm kiếm

Back
Top