All Packages Class Hierarchy This Package Previous Next Index
Class structure.DoublyLinkedList
java.lang.Object
|
+----structure.DoublyLinkedList
- public class DoublyLinkedList
- extends Object
- implements List
An implementation of lists that makes use of doubly linked elements.
This provided efficient implementation of both head and tail operations.
DoublyLinkedList()
- Constructs an empty list.
add(Object)
- Add a value 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 within the list.
elements()
- Construct an iterator to traverse the list.
isEmpty()
- Determine if the list is empty.
peek()
- Get a copy of the first value found in the list.
remove(Object)
- Remove a value from the list.
removeFromHead()
- Remove a value from the head of the list.
removeFromTail()
- Remove a value from the tail of the list.
size()
- Determine the number of elements in the list.
tailPeek()
- Get a copy of the last value found in the list.
toString()
- Construct a string representation of the list.
DoublyLinkedList
public DoublyLinkedList()
- Constructs an empty list.
- Postcondition:
- constructs an empty list
add
public void add(Object value)
- Add a value to the head of the list.
- Postcondition:
- adds value to beginning of list.
- Parameters:
- value - The value to be added.
- See Also:
- addToHead
addToHead
public void addToHead(Object value)
- Add a value to the head of the list.
- Precondition:
- value is not null
- Postcondition:
- adds element to head of list
- Parameters:
- value - The value to be added.
removeFromHead
public Object removeFromHead()
- Remove a value from the head of the list.
Value is returned.
- Precondition:
- list is not empty
- Postcondition:
- removes first value from list
- Returns:
- The value removed from the list.
addToTail
public void addToTail(Object value)
- Add a value to the tail of the list.
- Precondition:
- value is not null
- Postcondition:
- adds new value to tail of list
- Parameters:
- value - The value to be added.
removeFromTail
public Object removeFromTail()
- Remove a value from the tail of the list.
- Precondition:
- list is not empty
- Postcondition:
- removes value from tail of list
- Returns:
- The value removed from the list.
peek
public Object peek()
- Get a copy of the first value found in the list.
- Precondition:
- list is not empty
- Postcondition:
- returns first value in list.
- Returns:
- A reference to first value in list.
tailPeek
public Object tailPeek()
- Get a copy of the last value found in the list.
- Precondition:
- list is not empty
- Postcondition:
- returns last value in list.
- Returns:
- A reference to the last value in the list.
contains
public boolean contains(Object value)
- Check to see if a value is within the list.
- Precondition:
- value not null
- Postcondition:
- returns true iff value is in the list
- Parameters:
- value - A value to be found in the list.
- Returns:
- True if value is in list.
remove
public Object remove(Object value)
- Remove a value from the list. At most one value is removed.
Any duplicates remain. Because comparison is done with "equals,"
the actual value removed is returned for inspection.
- Precondition:
- value is not null. List can be empty.
- Postcondition:
- first element matching value is removed from list
- Parameters:
- value - The value to be removed.
- Returns:
- The value actually 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 found in the list.
isEmpty
public boolean isEmpty()
- Determine if the list is empty.
- Postcondition:
- returns true iff the list has no elements.
- Returns:
- True iff list has no values.
clear
public void clear()
- Remove all values from list.
- Postcondition:
- removes all the elements from the list
elements
public Iterator elements()
- Construct an iterator to traverse the list.
- Postcondition:
- returns iterator that allows the traversal of list.
- Returns:
- An iterator that traverses the list from head to tail.
toString
public String toString()
- Construct a string representation of the list.
- Postcondition:
- returns a string representing list
- Returns:
- A string representing the elements of the list.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index