dataStructures
Class Chain
java.lang.Object
|
+--dataStructures.Chain
- Direct Known Subclasses:
- ChainWithBinSort, ChainWithBinSort, DerivedLinkedStack, ExtendedChain, GraphChain
- public class Chain
- extends java.lang.Object
- implements LinearList
Field Summary |
protected dataStructures.ChainNode |
firstNode
|
protected int |
size
|
Constructor Summary |
Chain()
|
Chain(int initialCapacity)
create a list that is empty |
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 |
firstNode
protected dataStructures.ChainNode firstNode
size
protected int size
Chain
public Chain(int initialCapacity)
- create a list that is empty
Chain
public Chain()
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