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