All Packages Class Hierarchy This Package Previous Next Index
Class structure.SinglyLinkedList
java.lang.Object
|
+----structure.SinglyLinkedList
- public class SinglyLinkedList
- extends Object
- implements List
Singly linked lists have elements connected by a single reference.
They are space-efficient, but tail-related operations may be more
costly than with doubly linked lists.
- See Also:
- DoublyLinkedList
SinglyLinkedList()
- Construct an empty list.
add(Object)
- Add an object to the head of the list.
addToHead(Object)
- Add a value to the head of the list.
addToTail(Object)
- Add a value to the tail of the list.
clear()
- Remove all values from list.
contains(Object)
- Check to see if a value is in the list.
elements()
- Returns an iterator traversing list from head to tail.
isEmpty()
- Determine if list is empty.
peek()
- Fetch the first element of the list.
remove(Object)
- Remove a value from the list.
removeFromHead()
- Remove a value from the first element of the list.
removeFromTail()
- Remove the last value from the list.
size()
- Determine the number of elements in the list.
tailPeek()
- Fetch the last element of the list.
toString()
- Construct a string representing the list.
SinglyLinkedList
public SinglyLinkedList()
- Construct an empty list.
- Postcondition:
- generates an empty list.
add
public void add(Object value)
- Add an object to the head of the list.
- Postcondition:
- value is added to beginning of list (see addToHead)
- Parameters:
- value - The value to be added to the head of the list.
- See Also:
- addToHead
addToHead
public void addToHead(Object value)
- Add a value to the head of the list.
- Postcondition:
- value is added to beginning of list
- Parameters:
- value - The value to be added to the head of the list.
removeFromHead
public Object removeFromHead()
- Remove a value from the first element of the list.
- Precondition:
- list is not empty
- Postcondition:
- removes and returns value from beginning of list
- Returns:
- The value actually removed.
addToTail
public void addToTail(Object value)
- Add a value to the tail of the list.
- Postcondition:
- adds value to end of list
- Parameters:
- value - The value to be added to the tail of the list.
removeFromTail
public Object removeFromTail()
- Remove the last value from the list.
- Precondition:
- list is not empty
- Postcondition:
- removes the last value from the list
- Returns:
- The value actually removed.
peek
public Object peek()
- Fetch the first element of the list.
- Precondition:
- list is not empty
- Postcondition:
- returns first value in list
- Returns:
- A reference to first element of the list.
tailPeek
public Object tailPeek()
- Fetch the last element of the list.
- Precondition:
- list is not empty
- Postcondition:
- returns last value in list
- Returns:
- A reference to the last element of the list.
contains
public boolean contains(Object value)
- Check to see if a value is in the list.
- Precondition:
- value is not null
- Postcondition:
- returns true iff value is found in list.
- Parameters:
- value - The value sought.
- Returns:
- True if the value is within the list.
remove
public Object remove(Object value)
- Remove a value from the list. At most one value will be removed.
- Precondition:
- value is not null
- Postcondition:
- removes first element with matching value, if any.
- Parameters:
- value - The value to be removed.
- Returns:
- The actual value removed.
size
public int size()
- Determine the number of elements in the list.
- Postcondition:
- returns the number of elements in list
- Returns:
- The number of elements in the list.
isEmpty
public boolean isEmpty()
- Determine if list is empty.
- Postcondition:
- returns true iff the list is empty
- Returns:
- True iff the list is empty.
clear
public void clear()
- Remove all values from list.
- Postcondition:
- removes all elements from the list
elements
public Iterator elements()
- Returns an iterator traversing list from head to tail.
- Postcondition:
- returns enumeration allowing traversal of list
- Returns:
- An iterator to traverse list.
toString
public String toString()
- Construct a string representing the list.
- Postcondition:
- returns a string representing list
- Returns:
- A string representing the list.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index