Class MyList<AnyType>
java.lang.Object
MyList<AnyType>
- All Implemented Interfaces:
- java.lang.Iterable<AnyType>, SimpleList<AnyType>, SimpleQueue<AnyType>
public class MyList<AnyType>
- extends java.lang.Object
- implements SimpleList<AnyType>, SimpleQueue<AnyType>
A generic linked list class that you will write so that it implements
the SimpleList and SimpleQueue interfaces.
NAME:
Hours worked:
Method Summary |
boolean |
add(AnyType value)
Inserts a value at the end of the list. |
AnyType |
dequeue()
Retrieves and removes the first element of the queue |
void |
enqueue(AnyType value)
Inserts a value at the end of the queue |
boolean |
isEmpty()
Determine whether the list is empty. |
java.util.Iterator<AnyType> |
iterator()
Returns an Iterator object that iterates over the elements in this list
in proper sequence. |
static void |
main(java.lang.String[] args)
|
AnyType |
peek()
Retrieves, but does not rempve, the first element of the queue |
boolean |
remove(AnyType value)
Removes the first element of the list that is equal to value |
java.lang.String |
toString()
Returns a string representation of this linked list |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
MyList
public MyList()
isEmpty
public boolean isEmpty()
- Determine whether the list is empty.
- Specified by:
isEmpty
in interface SimpleList<AnyType>
- Specified by:
isEmpty
in interface SimpleQueue<AnyType>
- Returns:
- true if the list is empty, false otherwise
add
public boolean add(AnyType value)
- Inserts a value at the end of the list.
- Specified by:
add
in interface SimpleList<AnyType>
- Parameters:
value
- the element to be inserted into the list
- Returns:
- true if the value was added, false otherwise
remove
public boolean remove(AnyType value)
- Removes the first element of the list that is equal to value
- Specified by:
remove
in interface SimpleList<AnyType>
- Parameters:
value
- the object to remove
- Returns:
- true if the value was removed, false otherwise
enqueue
public void enqueue(AnyType value)
- Inserts a value at the end of the queue
- Specified by:
enqueue
in interface SimpleQueue<AnyType>
- Parameters:
value
- the element to be inserted into the queue
dequeue
public AnyType dequeue()
- Retrieves and removes the first element of the queue
- Specified by:
dequeue
in interface SimpleQueue<AnyType>
- Returns:
- the object at the front of the queue, or null if the queue is empty
peek
public AnyType peek()
- Retrieves, but does not rempve, the first element of the queue
- Specified by:
peek
in interface SimpleQueue<AnyType>
- Returns:
- the object at the front of the queue, or null if the queue is empty
iterator
public java.util.Iterator<AnyType> iterator()
- Returns an Iterator object that iterates over the elements in this list
in proper sequence. MUST be implemented since MyList implements both the
SimpleList and SimpleQueue interfaces, both of which extend Iterable
- Specified by:
iterator
in interface java.lang.Iterable<AnyType>
- Returns:
- an iterator over the elements in this list
toString
public java.lang.String toString()
- Returns a string representation of this linked list
- Overrides:
toString
in class java.lang.Object
- Returns:
- a string representation of this list
main
public static void main(java.lang.String[] args)