dataStructures
Class LinearListAsVector

java.lang.Object
  |
  +--dataStructures.LinearListAsVector

public class LinearListAsVector
extends java.lang.Object
implements LinearList


Field Summary
protected  java.util.Vector element
           
 
Constructor Summary
LinearListAsVector()
          create a list with initial capacity 10
LinearListAsVector(int initialCapacity)
          create a list with initial capacity initialCapacity
 
Method Summary
 void add(int index, java.lang.Object theElement)
          Insert an element with specified index.
 java.lang.Object get(int index)
           
 int indexOf(java.lang.Object theElement)
           
 boolean isEmpty()
           
static void main(java.lang.String[] args)
          test program
 java.lang.Object remove(int index)
          Remove the element with specified index.
 int size()
           
 java.lang.String toString()
          convert to a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

element

protected java.util.Vector element
Constructor Detail

LinearListAsVector

public LinearListAsVector(int initialCapacity)
create a list with initial capacity initialCapacity
Throws:
java.lang.IllegalArgumentException - when initialCapacity < 1

LinearListAsVector

public LinearListAsVector()
create a list with initial capacity 10
Method Detail

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface LinearList
Returns:
true iff list is empty

size

public int size()
Specified by:
size in interface LinearList
Returns:
current number of elements in list

get

public java.lang.Object get(int index)
Specified by:
get in interface LinearList
Returns:
element with specified index
Throws:
IndexOutOfBoundsException - when index is not between 0 and size - 1

indexOf

public int indexOf(java.lang.Object theElement)
Specified by:
indexOf in interface LinearList
Returns:
index of first occurrence of theElement, return -1 if theElement not in list

remove

public java.lang.Object remove(int index)
Remove the element with specified index. All elements with higher index have their index reduced by 1.
Specified by:
remove in interface LinearList
Throws:
IndexOutOfBoundsException - when index is not between 0 and size - 1 $return removed element

add

public void add(int index,
                java.lang.Object theElement)
Insert an element with specified index. All elements with equal or higher index have their index increased by 1.
Specified by:
add in interface LinearList
Throws:
IndexOutOfBoundsException - when index is not between 0 and size

toString

public java.lang.String toString()
convert to a string
Specified by:
toString in interface LinearList
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
test program