Skip to main content
1 of 4

Code Structure / Encapsulation

Class DLList representing your doubly-linked list implementation should be public.

Auxiliary classes should be encapsulated within the list as nested private static since they are only supposed to be used internally by the list.

External code should have no notion of list-nodes, list should be a designed as a user-friendly abstraction instead of leaking its implementation details.

Redundant Constructors

No-args constructors that only initialize attributes to default values defined by the language specification (such as null for reference types) only create noise. You don't need them, Java-compiler will autogenerate them for you.

E.g.:

NodePair() { beg = null; end = null; } 

Raw Types

You're using raw types in many places of the code.

  • NodePair should be declared as generic, as well as its fields.

  • Generic type variables are missing in the parameters type declarations in the splice() and sortr() methods (not a very discriptive name by the way).

Generic types should be provided while instantiating a generic class. Either explicitly (e.g. new DLNode<E>()), or through the type-inference mechanism by using so-called diamond operator which is more convenient.

  • DLNode<E> node = new DLNode(element); -> DLNode<E> node = new DLNode<>(element);

  • list = new <E> DLNode(); -> list = new DLNode<>();