datastructures

net.datastructures
Class NodeSequence

java.lang.Object
  extended bynet.datastructures.NodeList
      extended bynet.datastructures.NodeSequence
All Implemented Interfaces:
List, Sequence, Vector

public class NodeSequence
extends NodeList
implements Sequence

Implementation of a sequence by means of a doubly linked list.


Field Summary
 
Fields inherited from class net.datastructures.NodeList
header, numElts, trailer
 
Constructor Summary
NodeSequence()
           
 
Method Summary
 Position atRank(int rank)
          Returns the position containing the element at the given rank; O(n) time.
protected  void checkRank(int r, int n)
          Checks whether the given rank is in the range [0, n - 1]
 Object elemAtRank(int rank)
          Returns the element stored at the given rank; O(n) time
 void insertAtRank(int rank, Object element)
          Inserts an element at the given rank; O(n) time.
 int rankOf(Position p)
          Returns the rank of the element stored at the given position; O(n) time.
 Object removeAtRank(int rank)
          Removes the element stored at the given rank; O(n) time.
 Object replaceAtRank(int rank, Object element)
          Replaces the element stored at the given rank; O(n) time.
 
Methods inherited from class net.datastructures.NodeList
checkPosition, elements, first, insertAfter, insertBefore, insertFirst, insertLast, isEmpty, isFirst, isLast, last, next, positions, prev, remove, replace, size, swapElements, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.datastructures.List
elements, first, insertAfter, insertBefore, insertFirst, insertLast, isEmpty, last, next, positions, prev, remove, replace, size
 
Methods inherited from interface net.datastructures.Vector
isEmpty, size
 

Constructor Detail

NodeSequence

public NodeSequence()
Method Detail

checkRank

protected void checkRank(int r,
                         int n)
                  throws BoundaryViolationException
Checks whether the given rank is in the range [0, n - 1]

Throws:
BoundaryViolationException

atRank

public Position atRank(int rank)
Returns the position containing the element at the given rank; O(n) time.

Specified by:
atRank in interface Sequence

rankOf

public int rankOf(Position p)
           throws InvalidPositionException
Returns the rank of the element stored at the given position; O(n) time.

Specified by:
rankOf in interface Sequence
Throws:
InvalidPositionException

elemAtRank

public Object elemAtRank(int rank)
                  throws BoundaryViolationException
Returns the element stored at the given rank; O(n) time

Specified by:
elemAtRank in interface Vector
Parameters:
rank - Rank to query
Throws:
BoundaryViolationException - if r < 0 or r > Vector.size() - 1

insertAtRank

public void insertAtRank(int rank,
                         Object element)
                  throws BoundaryViolationException
Inserts an element at the given rank; O(n) time.

Specified by:
insertAtRank in interface Vector
Parameters:
rank - Rank at which to replace
Throws:
BoundaryViolationException - if r < 0 or r > Vector.size()

removeAtRank

public Object removeAtRank(int rank)
                    throws BoundaryViolationException
Removes the element stored at the given rank; O(n) time.

Specified by:
removeAtRank in interface Vector
Parameters:
rank - Rank at which to replace
Throws:
BoundaryViolationException - if r < 0 or r > Vector.size() - 1

replaceAtRank

public Object replaceAtRank(int rank,
                            Object element)
                     throws BoundaryViolationException
Replaces the element stored at the given rank; O(n) time.

Specified by:
replaceAtRank in interface Vector
Parameters:
rank - Rank at which to replace
Throws:
BoundaryViolationException - if r < 0 or r > Vector.size() - 1

datastructures