Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are not allowed to use any of the standard Java collection types ( like ArrayList ) for this assignment. You are also not allowed

You are not allowed to use any of the standard Java collection types (like ArrayList) for this assignment. You are also not allowed toStructure of the Methods
As described by the UML Class Diagram above, your MyArrayList class must have the following methods:
a public method named addToEnd that takes an object argument and returns nothing
a public method named insertat that takes an int argument and an object argument and returns nothing
a public method named removeAt that takes an int arguments and returns nothing
a public method named getit that takes an int argument and returns an Object
a public method named getsize that takes no arguments and returns an int
Note that:
these methods are declared in the MyList interface. You will be implementing these methods in this MyLinkedList concrete
derived class.
the getIterator method and the MyListIterator class are already implemented for you in the MyLinkedList class. Make no
changes to this code.
the Node class is already implemented for you in the MyLinkedList class. Make no changes to this code.
Additional Information
MyLinkedList
This concrete class will store its elements in Node objects. Each Node object has a dat a variable that stores the element and a next
variable that stores a reference to the next Node object in the list. Each instance of MyLinkedList has a Node variable called head.
When size is 0 then head is null. When size is not 0 then head is a reference to the first Node object. For each Node object in
the list, if this Node's next is null then this is the last Node in the list.
addToEnd method
Appends new item to end of list. For example: given the list {1,2,3} and an instruction to addToEnd (99), the result would
be this {1,2,3,99}.
this method will construct a new Node object who's data is the element to be added, and place this Nocle appropriately into the
list.
insertat method
Inserts a new Node at the specified index in the list. Given the list {1,2,3} and an instruction to insertat (1,99), the
result would be this {1,99,2,3}.
Throws a NoSuchElementException if the specified index is less than o or greater than size.
this method will construct a new Node object who's data is the element to be added, and place this Nocle appropriately into the
list.
removeat method
Removes the element at the specified index. For example: given the list {1,2,3} and an instruction to removeAt (1), the
result would be this {1,3}.
Throws a NoSuchElementException if the specified index is less than o or greater than or equal to size.
getAt method
Returns the item at the specified index. For example: given the list {1,2,3} and an instruction to getzt (1), the return
value would be 2.
Throws a NoSuchElementException if the specified index is less than o or greater than or equal to size.
getsize method
Returns the number of elements currently stored in the list.// Complete the implementation of your Mylinkedlist class in this file
public class MyLinkedList implements MyList ]
??? Implement the required fields and methods here
??? Do not alter the code below
public MyListiterator getiterator(){
return new MyLinkedListiterator();
}
private class MyLinkedListiterator implements MyListiterator {
Node currentNode = null;
@override
public object next(){
if (currentNode != null)
currentNode = currentNode.next;
else
currentNode = head;
return currentNode.data;
}
@override
public boolean hasNext(){
if (currentNode != nuli)
return currentNode.next != null;
else
return head != null;
}
}
class Node {
public object data = null;
public Node next = null;
}
}.?8
This interface specifies the basic operations of any list-like object.
This interface contains a variation of the methods of the
standard java.util. List interface.
**?
public
use arrays for this assignment.
Problem Description and Given Info
For this assignment you are given the following Java source code files:
MyListIterator.java (This file is complete - make no changes to this file)
MyList.java (This file is complete - make no changes to this file)
MyLinkedList.java (You must complete this file)
Main. java (You may use this file to write code to test your MyLinkedList)
You must complete the public class named MyLinkedList with fields and methods as defined below. Your MyLinkedList will
implement the MyList interface that is provided in the myList. java file.
UML CLass Diagram: MyLinkedList
Structure of the Fields
As described by the UML Class Diagram above, your MyLinkedLi st class must have the following fields:
a private field named head of type Node, initialized to nu11
a private field named size of type int, initialized to 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago