|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcalendar.MySortedLinkedList<T>
public class MySortedLinkedList<T>
This class represents a simple implementation of a sorted singly-linked list.
Elements added to the list are inserted in sorted order based on an specified
Comparator object.
This class relies on two classes: MyIterator and MyListNode. We have implemented
the MyListNode class for you, but you are responsible for the implementation
of the MyIterator class. Notice these are inner classes defined within the
MySortedLinkedList class. As a result they may access each other's fields even
if they are private. You are required to use the MyListNode class to implement
the nodes of your linked list.
Feel free to add any methods to the MySortedLinkedList class you consider are
necessary to implement your project. However, keep in mind that there are two
methods you are required to implement: an add method returning void (adds an element
to the list keeping the list sorted) and a remove method returning void (removes
any element(s) from the list that are equal to the parameter).
The JUnit public tests provide an example of using the MySortedLinkedList class.
You may not use the Java API LinkedList or ArrayList classes during the implementation
of the MySortedLinkedList class.
| Constructor Summary | |
|---|---|
MySortedLinkedList(java.util.Comparator<T> comparator)
Creates an empty list that is associated with the specified comparator. |
|
| Method Summary | |
|---|---|
void |
add(T element)
Inserts the specified element at the correct position in the sorted list. |
T |
get(int index)
Returns the element at the specified position in this list. |
boolean |
isEmpty()
|
java.util.Iterator<T> |
iterator()
Returns an iterator over the elements in this list (in proper sequence). |
void |
remove(T v)
Removes any elements matching given element |
int |
size()
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MySortedLinkedList(java.util.Comparator<T> comparator)
comparator - | Method Detail |
|---|
public void add(T element)
public T get(int index)
public void remove(T v)
public int size()
public boolean isEmpty()
public java.util.Iterator<T> iterator()
iterator in interface java.lang.Iterable<T>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||