dataStructures
Class ArrayLinearListWithIterator

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

public class ArrayLinearListWithIterator
extends java.lang.Object
implements LinearList


Field Summary
protected  java.lang.Object[] element
           
protected  int size
           
 
Constructor Summary
ArrayLinearListWithIterator()
          create a list with initial capacity 10
ArrayLinearListWithIterator(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()
           
 java.util.Iterator iterator()
          create and return an iterator
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.lang.Object[] element

size

protected int size
Constructor Detail

ArrayLinearListWithIterator

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

ArrayLinearListWithIterator

public ArrayLinearListWithIterator()
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
Returns:
removed element
Throws:
IndexOutOfBoundsException - when index is not between 0 and size - 1

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

iterator

public java.util.Iterator iterator()
create and return an iterator

main

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