Question: Can you help with this Java programming question. Implement a linked DoubleList class that extends the DoubleList class. You can test it using your own
Can you help with this Java programming question. Implement a linked DoubleList class that extends the DoubleList class. You can test it using your own main method. Also, I have attached the the double link class below for your reference.
/**
* A simple linked list structure of T objects. Only the
* T value contained in the list is visible through the standard
* list methods. Extends the DoubleLink class, which already
* defines the front node, rear node, length, isEmpty, and iterator.
*
*
* @param
* this data structure value type.
*/
public class DoubleList> extends DoubleLink {
/**
* Appends value to the rear of this List.
*
* @param value
* The value to append.
*/
public void append(final T value) {
// your code here
}
/**
* Removes duplicates from this List. The list contains one and only one of
* each value formerly present in this List. The first occurrence of each
* value is preserved.
*/
public void clean() {
// your code here
}
/**
* Combines contents of two lists into a third. Values are alternated from
* the source lists into this List. The source lists are empty when
* finished. NOTE: value must not be moved, only nodes.
*
* @param source1
* The first list to combine with this List.
* @param source2
* The second list to combine with this List.
*/
public void combine(final DoubleList source1,
final DoubleList source2) {
// your code here
}
/**
* Determines if this List contains key.
*
* @param key
* The key value to look for.
* @return true if key is in this List, false otherwise.
*/
public boolean contains(final T key) {
// your code here
}
/**
* Finds the number of times key appears in list.
*
* @param key
* The value to look for.
* @return The number of times key appears in this List.
*/
public int count(final T key) {
// your code here
}
/**
* Finds and returns the value in list that matches key.
*
* @param key
* The value to search for.
* @return The value that matches key, null otherwise.
*/
public T find(final T key) {
// your code here
}
/**
* Get the nth item in this List.
*
* @param n
* The index of the item to return.
* @return The nth item in this List.
* @throws ArrayIndexOutOfBoundsException
* if n is not a valid index.
*/
public T get(final int n) throws ArrayIndexOutOfBoundsException {
// your code here
}
/**
* Finds the first location of a value by key in this List.
*
* @param key
* The value to search for.
* @return The index of key in this List, -1 otherwise.
*/
public int index(final T key) {
// your code here
}
/**
* Inserts value into this List at index i. If i greater than the length of
* this List, append value to the end of this List. Accepts negative values:
* -1 is the rear, -2 is second from the end, etc.
*
* @param i
* The index to insert the new value at.
* @param value
* The new value to insert into this List.
*/
public void insert(int n, final T value) {
// your code here
}
/**
* Creates an intersection of two other Lists into this List. Copies value
* to this List. Source Lists are unchanged.
*
* @param source1
* The first List to create an intersection from.
* @param source2
* The second List to create an intersection from.
*/
public void intersection(final DoubleList source1,
final DoubleList source2) {
// your code here
}
/**
* Determines whether two lists are identical.
*
* @param that
* The list to compare against this List.
* @return true if this List contains the same values in the same order as
* that, false otherwise.
*/
public boolean isIdentical(final DoubleList that) {
// your code here
}
/**
* Finds the maximum value in this List.
*
* @return The maximum value.
*/
public T max() {
// your code here
}
/**
* Finds the minimum value in this List.
*
* @return The minimum value.
*/
public T min() {
// your code here
}
/**
* Adds a value to the front of this List.
*
* @param value
* The value to prepend.
*/
public void prepend(final T value) {
// your code here
}
/**
* Finds, removes, and returns the value in this List that matches key.
*
* @param key
* The value to search for.
* @return The value matching key, null otherwise.
*/
public T remove(final T key) {
// your code here
}
/**
* Removes the value at the front of this List.
*
* @return The value at the front of this List.
*/
public T removeFront() {
// your code here
}
/**
* Finds and removes all values in this List that match key.
*
* @param key
* The value to search for.
*/
public void removeMany(final T key) {
// your code here
}
/**
* Reverses the order of the values in this List.
*/
public void reverse() {
// your code here
}
/**
* Splits the contents of this List into the target Lists. Moves nodes only
* - does not move value or call the high-level methods insert or remove.
* this List is empty when done. The first half of this List is moved to
* target1, and the last half of this List is moved to target2. If the
* resulting lengths are not the same, target1 should have one more element
* than target2.
*
* @param target1
* The first List to move nodes to.
* @param target2
* The second List to move nodes to.
*/
public void split(final DoubleList target1,
final DoubleList target2) {
// your code here
}
/**
* Splits the contents of this List into the target Lists. Moves nodes only
* - does not move value or call the high-level methods insert or remove.
* this List is empty when done. Nodes are moved alternately from this List
* to target1 and target2.
*
* @param target1
* The first List to move nodes to.
* @param target2
* The second List to move nodes to.
*/
public void splitAlternate(final DoubleList target1,
final DoubleList target2) {
// your code here
}
/**
* Creates a union of two other Lists into this List. Copies value to this
* list. source Lists are unchanged.
*
* @param source1
* The first List to create a union from.
* @param source2
* The second List to create a union from.
*/
public void union(final DoubleList source1,
final DoubleList source2) {
// your code here
}
}
** DOUBLE LINK CLASS**
import java.lang.reflect.Array;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* The abstract base class for doubly-linked data structures. Provides
* attributes and implementations for getLength, isEmpty, toArray, and iterator
* methods. The front attribute is the first node in any
* doubly-linked list and rear the last node.
*
* @param
* data type for base data structure.
*/
public abstract class DoubleLink implements Iterable {
/**
* Creates an Iterator for the outer class. An iterator allows a program to
* walk through the data in a data structure by using the hasNext and next
* methods. Typical code:
*
*
Iterator iter = deque.iterator();
while(iter.hasNext()){
T data = iter.next();
...
}
*
*
* It also allows the user of the enhanced for loop:
*
*
for(T data : deque){
...
}
*
*
* (Replace T with a concrete class such as String or Integer.)
*/
private class DoubleLinkIterator implements Iterator {
// current is initialized to beginning of linked deque.
private DoubleNode current = DoubleLink.this.front;
/*
* (non-Javadoc)
*
* @see java.util.Iterator#hasNext()
*/
@Override
public boolean hasNext() {
return this.current != null;
}
/*
* (non-Javadoc)
*
* @see java.util.Iterator#next()
*/
@Override
public T next() {
T result = null;
if (this.current == null) {
throw new NoSuchElementException();
} else {
result = this.current.getValue();
this.current = this.current.getNext();
}
return result;
}
}
// First node of linked deque.
protected DoubleNode front = null;
// Number of elements currently stored in linked deque.
protected int length = 0;
// Last node of linked deque.
protected DoubleNode rear = null;
/**
* Returns the current number of elements in the linked structure.
*
* @return the value of length.
*/
public final int getLength() {
return this.length;
}
/**
* Determines whether the deque is empty or not.
*
* @return true if deque is empty, false otherwise.
*/
public final boolean isEmpty() {
return this.front == null;
}
/*
* (non-Javadoc)
*
* @see java.lang.Iterable#iterator()
*/
@Override
public final Iterator iterator() {
return new DoubleLinkIterator();
}
/**
* Returns an array of data from a deque. Not thread safe as it assumes
* contents of deque are not changed by an external thread during the copy
* loop. If data elements are added or removed by an external thread while
* the data is being copied to the array, then the declared array length may
* no longer be valid.
*
* @return an array of data of type T. Returns null if the deque is empty.
*/
@SuppressWarnings(\"unchecked\")
public final T[] toArray() {
T[] a = null;
if (this.front != null) {
// Create an array of data based upon the class of the head data.
a = (T[]) Array.newInstance(this.front.getValue().getClass(),
this.length);
final Iterator iter = this.iterator();
for (int i = 0; i
a[i] = iter.next();
}
}
return a;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
