A sequence is similar to a bag in the sense that both are collection data types, however, unlike a b

A sequence is similar to a bag in the sense that both are collection data types, however, unlike a bag, the elements in a sequence are arranged one after another. Using a linked list, implement a sequence data type named DoubleLinkedSeq to represent a sequence of elements of type double. The sequence can have a special “current element” which is specified and accessed through four methods start, getCurrent, advance and isCurrent.

The specification of DoubleLinkedSeq along with its implementation's template is given below. The specification and template for DoubleLinkedSeq is adapted from https://www.cs.colorado.edu/~main/edu/colorado/collections/DoubleLinkedSeq.java.

/******************************************************************************

* Limitations:

* Beyond Int.MAX_VALUE elements, the size method

* does not work.

*

* Note:

* This file contains only blank implementations (“stubs”)

* because this is a Programming Project for my students.

******************************************************************************/

public class DoubleLinkedSeq implements Cloneable

{   

/**

* Initialize an empty sequence.

* Postcondition:

* This sequence is empty.

**/   

public DoubleLinkedSeq( )

{

// Implemented by student.

}

/**

* Add a new element to this sequence, after the current element.

* Parameter: element

* the new element that is being added

* Postcondition:

* A new copy of the element has been added to this sequence. If there was

* a current element, then the new element is placed after the current

* element. If there was no current element, then the new element is placed

* at the end of the sequence. In all cases, the new element becomes the

* new current element of this sequence.

* Throws: OutOfMemoryError

* Indicates insufficient memory for a new node.

**/

public void addAfter(double element)

{

// Implemented by student.

}

/**

* Add a new element to this sequence, before the current element.

* Parameter: element

* the new element that is being added

* Postcondition:

* A new copy of the element has been added to this sequence. If there was

* a current element, then the new element is placed before the current

* element. If there was no current element, then the new element is placed

* at the start of the sequence. In all cases, the new element becomes the

* new current element of this sequence.

* Throws: OutOfMemoryError

* Indicates insufficient memory for a new node.

**/

public void addBefore(double element)

{

// Implemented by student.

}

/**

* Place the contents of another sequence at the end of this sequence.

* Parameter: addend

* a sequence whose contents will be placed at the end of this sequence

* Precondition:

* The parameter, addend, is not null.

* Postcondition:

* The elements from addend have been placed at the end of

* this sequence. The current element of this sequence remains where it

* was, and the addend is also unchanged.

* Throws: NullPointerException

* Indicates that addend is null.

* Throws: OutOfMemoryError

* Indicates insufficient memory to increase the size of this sequence.

**/

public void addAll(DoubleLinkedSeq addend)

{

// Implemented by student.

}

/**

* Move forward, so that the current element is now the next element in

* this sequence.

* Precondition:

* isCurrent() returns true.

* Postcondition:

* If the current element was already the end element of this sequence

* (with nothing after it), then there is no longer any current element.

* Otherwise, the new element is the element immediately after the

* original current element.

* Throws: IllegalStateException

* Indicates that there is no current element, so

* advance may not be called.

**/

public void advance( )

{

// Implemented by student.

}

/**

* Generate a copy of this sequence.

* Postcondition:

* The return value is a copy of this sequence. Subsequent changes to the

* copy will not affect the original, nor vice versa. Note that the return

* value must be type cast to a DoubleLinkedSeq before it can be used.

* Throws: OutOfMemoryError

* Indicates insufficient memory for creating the clone.

**/

public Object clone( )

{ // Clone a DoubleLinkedSeq object.

// Student will replace this return statement with their own code:

return null;

}

/**

* Create a new sequence that contains all the elements from one sequence

* followed by another.

* Parameter: s1

* the first of two sequences

* Parameter: s2

* the second of two sequences

* Precondition:

* Neither s1 nor s2 is null.

* Postcondition:

* returns a new sequence that has the elements of s1 followed by the

* elements of s2 (with no current element)

* Throws: NullPointerException

* Indicates that one of the arguments is null.

* Throws: OutOfMemoryError

* Indicates insufficient memory for the new sequence.

**/   

public static DoubleLinkedSeq catenation(DoubleLinkedSeq s1, DoubleLinkedSeq s2)

{

// Student will replace this return statement with their own code:

return null;

}

/**

* Accessor method to get the current element of this sequence.

* Precondition:

* isCurrent() returns true.

* Postcondition:

* returns the current element of this sequence

* Throws: IllegalStateException

* Indicates that there is no current element, so

* getCurrent may not be called.

**/

public double getCurrent( )

{

// Student will replace this return statement with their own code:

return 0;

}

/**

* Accessor method to determine whether this sequence has a specified

* current element that can be retrieved with the

* getCurrent method.

* Postcondition:

* returns true (there is a current element) or false (there is no current element at the moment)

**/

public boolean isCurrent( )

{

// Student will replace this return statement with their own code:

return 0;

}

/**

* Remove the current element from this sequence.

* Precondition:

* isCurrent() returns true.

* Postcondition:

* The current element has been removed from this sequence, and the

* following element (if there is one) is now the new current element.

* If there was no following element, then there is now no current

* element.

* Throws: IllegalStateException

* Indicates that there is no current element, so

* removeCurrent may not be called.

**/

public void removeCurrent( )

{

// Implemented by student.

}

/**

* Determine the number of elements in this sequence.

* Postcondition:

* returns the number of elements in this sequence

**/

public int size( )

{

// Student will replace this return statement with their own code:

return 0;

}

/**

* Set the current element at the front of this sequence.

* Postcondition:

* The front element of this sequence is now the current element (but

* if this sequence has no elements at all, then there is no current

* element).

**/

public void start( )

{

// Implemented by student.

}

}

To implement DoubleLinkedSeq class you also need to implement a DoubleNode class that represents a node with double values. Like, the previously discussed IntNode class, the DoubleNode represents a node in the linkedList, however, unlike IntNode that contains an integer element, DoubleNode contains a double element.