calendar
Class MySortedLinkedList<T>

java.lang.Object
  extended by calendar.MySortedLinkedList<T>
All Implemented Interfaces:
java.lang.Iterable<T>

public class MySortedLinkedList<T>
extends java.lang.Object
implements java.lang.Iterable<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.

Author:
Dept of Computer Science, UMCP

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

MySortedLinkedList

public MySortedLinkedList(java.util.Comparator<T> comparator)
Creates an empty list that is associated with the specified comparator.

Parameters:
comparator -
Method Detail

add

public void add(T element)
Inserts the specified element at the correct position in the sorted list.


get

public T get(int index)
Returns the element at the specified position in this list.


remove

public void remove(T v)
Removes any elements matching given element


size

public int size()

isEmpty

public boolean isEmpty()

iterator

public java.util.Iterator<T> iterator()
Returns an iterator over the elements in this list (in proper sequence).

Specified by:
iterator in interface java.lang.Iterable<T>
Returns:
iterator over the list


Web Accessibility