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

I have made 3 classes below The problem is when I Implement a method last in the

ID: 3631347 • Letter: I

Question

I have made 3 classes below
The problem is when I Implement a method last in the class linked list that returns an iterator to the last item in the list.
I do not get it. I will reward with a good rate if someone helps me to achieve this


class list node <AnyType>
{
/ / Constructors
public list node (AnyType theElement)
{
this (theElement, null);
}
public list node (AnyType theElement, list node <AnyType> n)
{
item = theElement;
next = n;
}
public AnyType element;
public list node <AnyType> next;
}
public class linked list <AnyType>
{
/ **
* Return an iterator Representing the header node.
* /
public LinkedListIterator <AnyType> zeroth ()
{
return new LinkedListIterator <AnyType> (header);
}
}
public class LinkedListIterator <AnyType>
{
public AnyType retrieve ()
{
return isValid ()? current.element: null;
}
List node <AnyType> CurrentVersion / / Current position
}

Explanation / Answer

You need to start at the "header" iterator and follow the next pointers until you encounter a next of "null", then return that iterator. public LinkedListIterator last () { list node p = header; while (p.next != null) { p = p.next; } return new LinkedListIterator (p); } }
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