Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java implement a linked list: The list interface defines what the methods are supposed to do: You are also given Node file: A node

Using Java implement a linked list:

The list interface defines what the methods are supposed to do:

image text in transcribed

image text in transcribed

image text in transcribed

You are also given Node file:

image text in transcribed

A node implementation file:

image text in transcribed

Fill out code to provide a linked list implementation of List (given above) that uses the Node implementation of the Node interface shown above. There is no need to change Node or Node Implementation in any way. The only code you should need to provide is the code for LinkedList.

public interface List { * Returns the number of elements in this list. * @return the number of elements in the list int size(); * Returns true if this list contains no elements. * @return true if this list contains no elements boolean isEmpty(); / stok * Removes all of the elements from this list. * void clear(); / * Returns true if this list contains the specified element. * @param element whose presence in this list is to be tested * @return true if this list contains the specified element boolean contains (T element); * Returns an array containing all of the elements of the list * in sequence. The size and contents of the array created * are the size and contents of the list at the time * that the method is called. * @return an array containing all of the elements in this * list in proper sequence T[] toArray(); * Appends the specified element to the end of this list. * @param element to be appended to this list, void add(t element); * Removes the first occurrence of the specified element * from this list, if it is present void add(t element); sek * Removes the first occurrence of the specified element * from this list, if it is present * @param element to be removed from this list, if present * @return true if this list contained the specified element and false otherwise boolean remove(t element); * Returns the element at the specified position in this list. * @param index of the element to return * @return the element at the specified position in this list I get(int index); * Replaces the element at the specified position in this list * with the specified element. * @param index of the element to replace * @param element to be stored at the specified position * @return the element previously at the specified position I set(int index, T element); * Inserts the specified element at the specified position in * this list (optional operation). Shifts the element currently * at that position (if any) and any subsequent elements to the * right (adds one to their indices). * The value of index must be in the range of 0 to the size of the * list. Adding an element at index size will add the element to * the end of the list. * @param index at which the specified element is to be inserted * @param element to be inserted void add(int index, T element); /** * Removes the element at the specified position in this list. * Shifts any subsequent elements to the left * (subtracts one from their indices). * @param index of the element to be removed * @return the element previously at the specified position I remove(int index); * Removes the first occurrence of the specified element from * this listif it is present. * @param element to search for * @return the index of the first occurrence of the specified * element in this list, or -1 if this list does not contain * the element. int indexOf(T element); * Returns the index of the first occurrence of the specified * element in this list, or -1 if this list does not contain * the element. * @param element to search for * @return the index of the last occurrence of the specified * element in this list, or -1 if this list does not contain * the element s / int lastIndexOf(T element); public interface Node { I getValue(); void setValue(T value); Node getNext(); void setNext (Node next); default boolean hasNext() { return (getNext() != null); public class NodeImpl implements Node { private T _value; private Node _next; public Node Impl(T value, Node next) { _value = value; _next = next; @Override public I getValue() { return _value; @Override public void setValue(T value) { _value = value; @Override public Node getNext() { return _next; @Override public void setNext (Node next) { _next = next; public interface List { * Returns the number of elements in this list. * @return the number of elements in the list int size(); * Returns true if this list contains no elements. * @return true if this list contains no elements boolean isEmpty(); / stok * Removes all of the elements from this list. * void clear(); / * Returns true if this list contains the specified element. * @param element whose presence in this list is to be tested * @return true if this list contains the specified element boolean contains (T element); * Returns an array containing all of the elements of the list * in sequence. The size and contents of the array created * are the size and contents of the list at the time * that the method is called. * @return an array containing all of the elements in this * list in proper sequence T[] toArray(); * Appends the specified element to the end of this list. * @param element to be appended to this list, void add(t element); * Removes the first occurrence of the specified element * from this list, if it is present void add(t element); sek * Removes the first occurrence of the specified element * from this list, if it is present * @param element to be removed from this list, if present * @return true if this list contained the specified element and false otherwise boolean remove(t element); * Returns the element at the specified position in this list. * @param index of the element to return * @return the element at the specified position in this list I get(int index); * Replaces the element at the specified position in this list * with the specified element. * @param index of the element to replace * @param element to be stored at the specified position * @return the element previously at the specified position I set(int index, T element); * Inserts the specified element at the specified position in * this list (optional operation). Shifts the element currently * at that position (if any) and any subsequent elements to the * right (adds one to their indices). * The value of index must be in the range of 0 to the size of the * list. Adding an element at index size will add the element to * the end of the list. * @param index at which the specified element is to be inserted * @param element to be inserted void add(int index, T element); /** * Removes the element at the specified position in this list. * Shifts any subsequent elements to the left * (subtracts one from their indices). * @param index of the element to be removed * @return the element previously at the specified position I remove(int index); * Removes the first occurrence of the specified element from * this listif it is present. * @param element to search for * @return the index of the first occurrence of the specified * element in this list, or -1 if this list does not contain * the element. int indexOf(T element); * Returns the index of the first occurrence of the specified * element in this list, or -1 if this list does not contain * the element. * @param element to search for * @return the index of the last occurrence of the specified * element in this list, or -1 if this list does not contain * the element s / int lastIndexOf(T element); public interface Node { I getValue(); void setValue(T value); Node getNext(); void setNext (Node next); default boolean hasNext() { return (getNext() != null); public class NodeImpl implements Node { private T _value; private Node _next; public Node Impl(T value, Node next) { _value = value; _next = next; @Override public I getValue() { return _value; @Override public void setValue(T value) { _value = value; @Override public Node getNext() { return _next; @Override public void setNext (Node next) { _next = next

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

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions

Question

When should you avoid using exhaust brake select all that apply

Answered: 1 week ago

Question

What is ethnocentric bias?

Answered: 1 week ago