Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me with the methods: public Object[] toArray(),public boolean remove(Object o), public E remove(int index), public void add(int index, E element), public boolean

Can someone help me with the methods: public Object[] toArray(),public boolean remove(Object o), public E remove(int index), public void add(int index, E element),
public boolean addAll(CiscList c)
package edu.ust.cisc; import java.util.Iterator; import java.util.NoSuchElementException; /** * This class implements an acyclic (non-cyclic), doubly-linked list. * @param  */ public class CiscDoublyLinkedList extends CiscAbstractList { /** * A reference to the first node in the list (or null if list is empty). */ private Node head; /** * A reference to the last node int the list (or null if list is empty). */ private Node tail; /** * Number of elements in the list. */ private int size; /** * Returns the number of elements in this list. * * @return the number of elements in this list */ @Override public int size() { return 0; } /** * Returns {@code true} if this list contains no elements. * * @return {@code true} if this list contains no elements */ @Override public boolean isEmpty() { return false; } /** * Returns {@code true} if this list contains the specified element (compared using the {@code equals} method). * * @param o element whose presence in this list is to be tested * @return {@code true} if this list contains the specified element * @throws NullPointerException if the specified element is null */ @Override public boolean contains(Object o) { return false; } /** * Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not * contain the element (compared using the {@code equals} method). * * @param o 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 * @throws NullPointerException if the specified element is null */ @Override public int indexOf(Object o) { return 0; } /** * Removes all of the elements from this list. The list will be empty after this call returns. */ @Override public void clear() { } /** * Returns the element at the specified position in this list. * * @param index index of the element to return * @return the element at the specified position in this list * @throws IndexOutOfBoundsException if the index is out of range */ @Override public E get(int index) { return null; } /** * Appends the specified element to the end of this list. * * 

Lists may place the specified element at arbitrary locations if desired. In particular, an ordered list will * insert the specified element at its sorted location. List classes should clearly specify in their documentation * how elements will be added to the list if different from the default behavior (end of this list). * * @param e element to be appended to this list * @return {@code true} * @throws NullPointerException if the specified element is null */ @Override public boolean add(E e) { return false; } /** * Replaces the element at the specified position in this list with the specified element (optional operation). * * @param index index of the element to replace * @param element element to be stored at the specified position * @return the element previously at the specified position * @throws UnsupportedOperationException if the {@code set} operation is not supported by this list * @throws NullPointerException if the specified element is null * @throws IndexOutOfBoundsException if the index is out of range */ @Override public E set(int index, E element) { return null; } /** * Returns an array containing all of the elements in this list in proper sequence (from first to last element). * *

The returned array will be "safe" in that no references to it are maintained by this list. (In other words, * this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify * the returned array. * * @return an array containing all of the elements in this list in proper sequence */ @Override public Object[] toArray() { return new Object[0]; } /** * Removes the first occurrence of the specified element from this list, if it is present. If this list does not * contain the element, it is unchanged. Returns {@code true} if this list contained the specified element. * * @param o element to be removed from this list, if present * @return {@code true} if this list contained the specified element * @throws NullPointerException if the specified element is null */ @Override public boolean remove(Object o) { return false; } /** * Removes the element at the specified position in this list. Shifts any subsequent elements to the left * (subtracts one from their indices). Returns the element that was removed from the list. * * @param index the index of the element to be removed * @return the element previously at the specified position * @throws IndexOutOfBoundsException if the index is out of range */ @Override public E remove(int index) { return null; } /** * 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). * * @param index index at which the specified element is to be inserted * @param element element to be inserted * @throws UnsupportedOperationException if the {@code add} operation is not supported by this list * @throws NullPointerException if the specified element is null * @throws IndexOutOfBoundsException if the index is out of range */ @Override public void add(int index, E element) { } /** * Appends all elements in the specified list to the end of this list, in the order that they are returned by the * specified list's iterator (optional operation). * * @param c list containing elements to be added to this list * @return {@code true} if this list changed as a result of the call * @throws UnsupportedOperationException if the {@code addAll} operation is not supported by this list * @throws NullPointerException if the specified list is null */ @Override public boolean addAll(CiscList c) { return false; } /** * Returns an iterator over the elements in this list in proper sequence. * * @return an iterator over the elements in this list in proper sequence */ @Override public Iterator iterator() { return null; } private static class CiscDoublyLinkedListIterator implements Iterator { /** * A reference to the node containing the next element to return. */ private Node nextNode; /** * Constructs an iterator beginning at the specified node. */ public CiscDoublyLinkedListIterator(Node head) { } /** * Returns {@code true} if the iteration has more elements. * (In other words, returns {@code true} if {@link #next} would * return an element rather than throwing an exception.) * * @return {@code true} if the iteration has more elements */ @Override public boolean hasNext() { return false; } /** * Returns the next element in the iteration. * * @return the next element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ @Override public E next() { return null; } } private static class Node { private E data; private Node next; private Node prev; private Node(E data, Node next, Node prev) { this.data = data; this.next = next; this.prev = prev; } } }

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

Students also viewed these Databases questions