dataStructures
Class FastArrayLinearList
java.lang.Object
|
+--dataStructures.FastArrayLinearList
- public class FastArrayLinearList
- extends java.lang.Object
- implements LinearList
Field Summary |
protected java.lang.Object[] |
element
|
protected int |
size
|
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 |
element
protected java.lang.Object[] element
size
protected int size
FastArrayLinearList
public FastArrayLinearList(int initialCapacity)
- create a list with initial capacity initialCapacity
- Throws:
- java.lang.IllegalArgumentException - when
initialCapacity < 1
FastArrayLinearList
public FastArrayLinearList()
- create a list with initial capacity 10
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
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