// File: DoubleLinkedSeq.java from the package edu.colorado.collections
// This is an assignment for students to complete after reading Chapter 4 of
// "Data Structures and Other Objects Using Java" by Michael Main.
// Check with your instructor to see whether you should put this class in
// a package. At the moment, it is declared as part of edu.colorado.collections:
package edu.colorado.collections;
/******************************************************************************
* This class is a homework assignment;
* A DoubleLinkedSeq
is a collection of double
numbers.
* The sequence can have a special "current element," which is specified and
* accessed through four methods that are not available in the sequence class
* (start, getCurrent, advance and isCurrent).
*
* 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.
*
* @version Feb 10, 2016
******************************************************************************/
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.
* @param 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.
* @exception OutOfMemoryError
* Indicates insufficient memory for a new node.
**/
public void addAfter(int element)
{
// Implemented by student.
}
/**
* Add a new element to this sequence, before the current element.
* @param 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.
* @exception OutOfMemoryError
* Indicates insufficient memory for a new node.
**/
public void addBefore(int element)
{
// Implemented by student.
}
/**
* Place the contents of another sequence at the end of this sequence.
* @param 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.
* @exception NullPointerException
* Indicates that addend
is null.
* @exception 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.
* @exception 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.
* @return
* 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.
* @exception 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.
* @param s1
* the first of two sequences
* @param s2
* the second of two sequences
* Precondition:
* Neither s1 nor s2 is null.
* @return
* a new sequence that has the elements of s1
followed by the
* elements of s2
(with no current element)
* @exception NullPointerException
* Indicates that one of the arguments is null.
* @exception 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.
* @return
* the current capacity of this sequence
* @exception 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.
* @return
* true (there is a current element) or false (there is no current element at the moment)
**/
public double 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.
* @exception 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.
* @return
* 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.
}
}