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

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

ID: 3909375 • Letter: 6

Question

6 Complete the methods below 7None of the methods should modify the list, unless that is the purpose of the method * You may not add any fields to the node or list classes. * You may not add any methods to the node class. 9 12 You MAY add private methods to the list class (helper functions for the recursion) 13 *1 14 ? public class MyLinked { 15static class Node 16 17 18 19 20 21 public Node (double item, Node next) public double item; public Node next; this.item -item; this.next - next; h int N; Node first;

Explanation / Answer

public void deleteFirst()
{
if (first == null)
{
System.out.println("List is empty");
}
else
{
first = first.next;
N = N-1;
}
}

public void delete(int k)
{
int count = 1;
Node previous = null;
Node current = first;
if (k<0 || k>=N)
{
throw new IllegalArgumentException();
}
else if (k==1)
{
deleteFirst();
}
else
{
while (count == k)
{
previous = current;
current = current.next;
count++;
}
previous.next = current.next;

N = N-1;
}
}

public void reverse()
{
Node previous = null, current = first,next = null;
while (current != null)
{
next = current.next;
current.next = previous;
previous = current;
current = next;
}
first = prev;
}

public void remove(double item)
{
int count = 1;
Node temp = first;
while(temp != null)
{
if (temp.item == item)
{
delete(count);
count--;
}
count++;
temp = temp.next;
}
}

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