Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The MyLinkedListclass used in our class example is a one-way linkedlist whichallows traversal from the front to theback.Please write a report to discuss the following

The MyLinkedListclass used in our class example is a one-way linkedlist whichallows traversal from the front to theback.Please write a report to discuss the following listed items:

The relationship between MyLinkedList and MyList as well as the methods defined in them.

The relationship between MyLinkedList and Iterable as well as the methods defined in them.

How traversal from the beginning to the endcan be conducted with MyLinkedList?

Please use diagrams to explain how a new item is inserted to a linkedlistin various cases.You need to include nodes to explain.

Please use diagrams to explain how an existing item is removed from a linkedlist in various cases.

You need to include nodes to explain.

image text in transcribedimage text in transcribed

Page 1 > of 2 ZOOM + import java.util.collection; public interface MyList extends Collection { /** Add a new element at the specified index in this list */ public void add(int index, Ee); /** Return the element from this list at the specified index */ public E get(int index); /** Return the index of the first matching element in this list. Return -1 if no match. */ public int indexOf(object e); /** Return the index of the last matching element in this list Return -1 if no match. */ public int lastIndexOf(E e); /** Remove the element at the specified position in this list Shift any subsequent elements to the left. Return the element that was removed from the list. */ public E remove(int index); /** Replace the element at the specified position in this list with the specified element and returns the new set. */ public E set(int index, Ee); @Override /** Add a new element at the end of this list */ public default boolean add(E e) { add(size(), e); return true; } @Override /** Return true if this list contains no elements */ public default boolean isEmpty() { return size() == 0; } Page 2 > of 2 ZOOM + @Override /** Remove the first occurrence of the element e from this list. Shift any subsequent elements to the left. Return true if the element is removed. */ public default boolean remove(Object e) { if (indexOf(e) >= 0) { remove(indexOf(e)); return true; } else return false; } @Override public default boolean containsAll(Collection> c) { // Left as an exercise return true; @Override public default boolean addAll(Collections? extends > c) { // Left as an exercise return true; } @Override public default boolean removeAll(Collection> c) { // Left as an exercise return true; @Override public default boolean retainAll(Collection> c) { // Left as an exercise return true; @Override public default object[] toArray() { // Left as an exercise E[] anArr = (E[]) new Object[size() ; for(int i = 0; i E[] toArray(E[] array) { // Left as an exercise E[] anArr = (E[]) new Object[array.Length) ; for(int i = 0; i of 2 ZOOM + import java.util.collection; public interface MyList extends Collection { /** Add a new element at the specified index in this list */ public void add(int index, Ee); /** Return the element from this list at the specified index */ public E get(int index); /** Return the index of the first matching element in this list. Return -1 if no match. */ public int indexOf(object e); /** Return the index of the last matching element in this list Return -1 if no match. */ public int lastIndexOf(E e); /** Remove the element at the specified position in this list Shift any subsequent elements to the left. Return the element that was removed from the list. */ public E remove(int index); /** Replace the element at the specified position in this list with the specified element and returns the new set. */ public E set(int index, Ee); @Override /** Add a new element at the end of this list */ public default boolean add(E e) { add(size(), e); return true; } @Override /** Return true if this list contains no elements */ public default boolean isEmpty() { return size() == 0; } Page 2 > of 2 ZOOM + @Override /** Remove the first occurrence of the element e from this list. Shift any subsequent elements to the left. Return true if the element is removed. */ public default boolean remove(Object e) { if (indexOf(e) >= 0) { remove(indexOf(e)); return true; } else return false; } @Override public default boolean containsAll(Collection> c) { // Left as an exercise return true; @Override public default boolean addAll(Collections? extends > c) { // Left as an exercise return true; } @Override public default boolean removeAll(Collection> c) { // Left as an exercise return true; @Override public default boolean retainAll(Collection> c) { // Left as an exercise return true; @Override public default object[] toArray() { // Left as an exercise E[] anArr = (E[]) new Object[size() ; for(int i = 0; i E[] toArray(E[] array) { // Left as an exercise E[] anArr = (E[]) new Object[array.Length) ; for(int i = 0; i

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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

Calculate 2/3 5/6 7/15.

Answered: 1 week ago

Question

2 What are the implications for logistics strategy?

Answered: 1 week ago