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

Hello I suffer with this task and could really need someone who knows more about

ID: 3633455 • Letter: H

Question

Hello

I suffer with this task and could really need someone who knows more about this than me.

The task reads like this:

Create a method removeSubList in class LinkedList that takes two iterators as input, respectively, start and end of SubList to be removed.
Then Implement a method retreat () in class LinkedList that takes an iterator and returns an iterator pointing at the item above.


These are classes that are added with this task:


class ListNode<AnyType>
{
// Constructors
public ListNode( AnyType theElement )
{
this( theElement, null );
}
public ListNode( AnyType theElement, ListNode<AnyType> n )
{
element = theElement;
next = n;
}
public AnyType element;
public ListNode<AnyType> next;
}
public class LinkedList<AnyType>
{
/**
* Return an iterator representing the header node.
*/
public LinkedListIterator <AnyType> last ()
{
list node; p = header;
while (p.next != null) {
p = p.next;
}
return new LinkedListIterator <AnyType> (p);
}
}
}
public class LinkedListIterator<AnyType>
{
public AnyType retrieve( )
{
return isValid( ) ? current.element : null;
}
ListNode<AnyType> current; // Current position
}

Explanation / Answer

import java.util.*; //Create class public class remove{ //Main method public static void main (String args[]){ //Craete ArrayList object ArrayList arr = new ArrayList(); //Display output System.out.println("Total elements of iterator: "); for (int i = 1; i < 10; i++) arr.add(i); int count = 0; for (Iterator i = arr.iterator(); i.hasNext();){ System.out.println ("element is " + i.next()); } System.out.println("After removing : "); for (Iterator i = arr.iterator(); i.hasNext();){ count++; i.next(); if (count%4 == 0) i.remove(); } for (Iterator i = arr.iterator(); i.hasNext();){ System.out.println ("element is " + i.next()); } } } ======================================================================= Remove an element from Collection using Java Iterator Example /* Remove an element from Collection using Java Iterator Example This Java Example shows how to remove an element from underlying Collection using Java Iterator's remove method. */ import java.util.Iterator; import java.util.ArrayList; public class RemoveElementThroughIteratorExample { public static void main(String[] args) { //create an ArrayList object ArrayList aList = new ArrayList(); //populate ArrayList object aList.add("1"); aList.add("2"); aList.add("3"); aList.add("4"); aList.add("5"); System.out.println("ArrayList before removal : "); for(int i=0; i
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