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

Constructor Index

 o SinglyLinkedList()
Construct an empty list.

Method Index

 o add(Object)
Add an object to the head of the list.
 o addToHead(Object)
Add a value to the head of the list.
 o addToTail(Object)
Add a value to the tail of the list.
 o clear()
Remove all values from list.
 o contains(Object)
Check to see if a value is in the list.
 o elements()
Returns an iterator traversing list from head to tail.
 o isEmpty()
Determine if list is empty.
 o peek()
Fetch the first element of the list.
 o remove(Object)
Remove a value from the list.
 o removeFromHead()
Remove a value from the first element of the list.
 o removeFromTail()
Remove the last value from the list.
 o size()
Determine the number of elements in the list.
 o tailPeek()
Fetch the last element of the list.
 o toString()
Construct a string representing the list.

Constructors

 o SinglyLinkedList
public SinglyLinkedList()
Construct an empty list.

Postcondition:
generates an empty list.

Methods

 o 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
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o isEmpty
public boolean isEmpty()
Determine if list is empty.

Postcondition:
returns true iff the list is empty

Returns:
True iff the list is empty.
 o clear
public void clear()
Remove all values from list.

Postcondition:
removes all elements from the list

 o 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.
 o 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