Answer to Question #62294 in Java | JSP | JSF for Paul

Question #62294
Give an implementation of the size() method for the singularly linked list class, assuming that we did not maintain size as an instance variable
1
Expert's answer
2016-09-29T14:16:03-0400
public int size() {
Node<AnyType> tmp = head;
int size = 0;
if (head == null) {
return size;
} else {
size++;
while (tmp.next != null) {
tmp = tmp.next;
size++;
}
}
return size;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS