Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6 Complete the methods below. 7 None of the methods should modify the list, unle

ID: 3909254 • Letter: 6

Question

6 Complete the methods below. 7 None of the methods should modify the list, unless that is the purpose of the method 8 9You may not add any fields to the node or list classes You may not add any methods to the node class. * 12 * You MAY add private methods to the list class (helper functions for the recursion). 13 4 public class MyLinked 15 ? static class Node public Node (double item, Node next) { this. item = item; this. next = next public double item; public Node next; L6 int N Node first; // write a function to compute the size of the list, using a loop // empty list has size o public int sizeLoop ) return StdRandom.uniform (100); I/TODO: fix this 28 29 / write a function to compute the size of the list, using an optimistic, forward recursion // empty list has size ? public int sizeForward )[ 82 ? return StdRandom.uniform (100) //TODO: fix this 35 36 37 // write a function to compute the size of the list, using an optimistic, backward recursion // empty list has size public int sizeBackward) 38 ? return StdRandom.uniform (100); I/TODO: fix this 39 40

Explanation / Answer

public class MyLinked{

static class Node{

public Node (double item, Node next){this.item=item;this.next=next}

public double item;

public Node next;

}

int N;

Node first;

public int sizeLoop(){

int size = 0;

LinkedList current = this;

while(Current.next != null)

{

Current = Current.next;

size++;

}

return size;

}

public int sizeForward(){

Node new_node = new Node(new_data);

new_node.next = head;

head = new_node;

if (node == null)

return 0;

return 1 + getCountRec(node.next);

return getCountRec(head);

}

public int sizeBackward(){

Node prev = null;

Node current = node;

Node next = null;

while (current != null) {

next = current.next;

current.next = prev;

prev = current;

current = next;

}

node = prev;

return node;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote