Interface ListADT<E>


public interface ListADT<E>

A List is an ordered collection of items.


Method Summary
 void add(E item)
          Add item to the end of the List.
 void add(int pos, E item)
          Add item at position pos in the List, moving the items originally in positions pos through size() - 1one place to the right to make room.
 boolean contains(E item)
          Return true iff item is in the List (i.e., there is an item x in the List such that x.equals(item))
 E get(int pos)
          Return the item at position pos in the List.
 boolean isEmpty()
          Return true iff the List is empty.
 E remove(int pos)
          Remove and return the item at position pos in the List, moving the items originally in positions pos+1 through size() - 1one place to the left to fill in the gap.
 int size()
          Return the number of items in the List.
 

Method Detail

add

void add(E item)
Add item to the end of the List.

Parameters:
item - the item to add

add

void add(int pos,
         E item)
Add item at position pos in the List, moving the items originally in positions pos through size() - 1one place to the right to make room.

Parameters:
pos - the position at which to add the item
item - the item to add
Throws:
java.lang.IndexOutOfBoundsException - if pos is less than 0 or greater than size()

contains

boolean contains(E item)
Return true iff item is in the List (i.e., there is an item x in the List such that x.equals(item))

Parameters:
item - the item to check
Returns:
true if item is in the List, false otherwise

size

int size()
Return the number of items in the List.

Returns:
the number of items in the List

isEmpty

boolean isEmpty()
Return true iff the List is empty.

Returns:
true if the List is empty, false otherwise

get

E get(int pos)
Return the item at position pos in the List.

Parameters:
pos - the position of the item to return
Returns:
the item at position pos
Throws:
java.lang.IndexOutOfBoundsException - if pos is less than 0 or greater than or equal to size()

remove

E remove(int pos)
Remove and return the item at position pos in the List, moving the items originally in positions pos+1 through size() - 1one place to the left to fill in the gap.

Parameters:
pos - the position at which to remove the item
Returns:
the item at position pos
Throws:
java.lang.IndexOutOfBoundsException - if pos is less than 0 or greater than or equal to size()