In Java please. Do NOT add any fields to the node or list classes. Do NOT add an
ID: 3594381 • Letter: I
Question
In Java please. Do NOT add any fields to the node or list classes.
Do NOT add any methods to the node class.
*You MAY add private methods to the class (helper functions for the recursion) static boolean showMeSuccess-false; // set to true to also see Success notifications for tests // set to false to only see Failure notifications for tests static class Node public Node (double item, Node next) this.item item; this.next next; h public double item; public Node next; Node first; // a function to compute the size of the list, using a loop // an empty list has size public int sizeIterative (O return StdRandom.uniform (100); I/TODO 1: fix thisExplanation / Answer
public int sizeIterative() {
if (first == null) return 0;
Node cur = first;
int size = 0;
while(cur!=null) {
size = size+1;
cur = cur.next;
}
return size;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.