dataStructures
Class VectorLinearList
java.lang.Object
|
+--dataStructures.VectorLinearList
- public class VectorLinearList
- extends java.lang.Object
- implements LinearList
Field Summary |
protected java.util.Vector |
element
|
Constructor Summary |
VectorLinearList()
create a list with initial capacity 10 |
VectorLinearList(int initialCapacity)
create a list with initial capacity initialCapacity |
Method Summary |
java.lang.Object |
elementAt(int index)
|
java.util.Enumeration |
elements()
create and return an enumerator |
int |
indexOf(java.lang.Object elem)
|
void |
insertElementAt(java.lang.Object obj,
int index)
Insert an element with specified index. |
boolean |
isEmpty()
|
static void |
main(java.lang.String[] args)
test program |
void |
removeElementAt(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.util.Vector element
VectorLinearList
public VectorLinearList(int initialCapacity)
- create a list with initial capacity initialCapacity
- Throws:
- java.lang.IllegalArgumentException - thrown
if initialCapacity < 1
VectorLinearList
public VectorLinearList()
- 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
elementAt
public java.lang.Object elementAt(int index)
- Returns:
- element with specified index
- Throws:
- java.lang.IllegalArgumentException - thrown
if index is not between 0 and size - 1
indexOf
public int indexOf(java.lang.Object elem)
- Specified by:
- indexOf in interface LinearList
- Returns:
- index of first occurrence of elem,
return -1 if elem not in list
removeElementAt
public void removeElementAt(int index)
- Remove the element with specified index.
All elements with higher index have their
index reduced by 1.
- Throws:
- java.lang.IllegalArgumentException - thrown
if index is not between 0 and size - 1
insertElementAt
public void insertElementAt(java.lang.Object obj,
int index)
- Insert an element with specified index.
All elements with equal or higher index
have their index increased by 1.
- Throws:
- java.lang.IllegalArgumentException - thrown
if 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
elements
public java.util.Enumeration elements()
- create and return an enumerator
main
public static void main(java.lang.String[] args)
- test program