public class DLList<E extends Comparable<? super E>> public class DLList<E extends Comparable<? super E>> A better option would be to use a Comparator to determine the ordering of elements.
If you choose this route, your list would need to expose a constructor expecting a Comparator as a parameter.
public class DLList<E> { private final Comparator<? super E> comparator; } public class DLList<E> { private final Comparator<? super E> comparator; } Where Comparator<? super E> means that this comparator is capable of dialing with instances of type E or one of its super-typetypes.
If you choose this route, your list would need to expose a constructor expecting a Comparator as a parameter.
Optionally it might also expose a constructor which does not require a comparator, and in such a case while sorting elements they should be treated as comparable; i.e. you need to cast the values of nodes into a Comparable of raw type. That's one of the rare cases when use raw types is justifiable (but you have many others that are not, more on that below), and don't forget to apply annotation @SuppressWarnings("unchecked") while performing this cast.
Redundant Constructors / Initialization to null
No-args constructors that only initialize attributes to default values defined by the language specification (such as null for reference types) only create noise.
- No-args constructors (in classes that do not declare parameterized constructors), which initialize attributes to default values defined by the language specification (such as
nullfor reference types) only create noise.
NodePair() { beg = null; end = null; } - When a class has more than one constructor, you can call constructors from one another (so-called telescopic constructors). But, please, doesn't perform the automatic assignment to
nullmanually. If a developer has chosen to use a certain technology (language, framework), it should be well-understood and trusted.
For instanceSo instead of this:
NodePair() { beg = null; end = null; } DLNode() { next = null; prev = null; element = null; } DLNode(E e) { next = null; prev = null; element = e; } I'll suggest the following:
DLNode() { this(null); } DLNode(E e) { element = e; }