All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jdsl.core.algo.sorts.ListInsertionSort

java.lang.Object
   |
   +----jdsl.core.algo.sorts.ListInsertionSort

public class ListInsertionSort
extends Object
implements SortObject

Constructor Index

 o ListInsertionSort()

Method Index

 o sort(Sequence, Comparator)
Perform insertion-sort, assuming the Sequence is based on a doubly-linked list.

The sort proceeds by looking at each element in S, removing it, and inserting it in its place in a sorted sequence on the side.

Constructors

 o ListInsertionSort
 public ListInsertionSort()

Methods

 o sort
 public void sort(Sequence S,
                  Comparator c)
Perform insertion-sort, assuming the Sequence is based on a doubly-linked list.

The sort proceeds by looking at each element in S, removing it, and inserting it in its place in a sorted sequence on the side. Once S has been emptied, the temporary sequence is sorted; move all its elements back to S. This sort also demonstrates the use of a sentinel: to avoid unnecessary checks for the end of the temporary sequence, we insert an element as big as the biggest element, guaranteeing that no element will be inserted after it. This element is removed before copying back into S, to avoid changing S's contents.


All Packages  Class Hierarchy  This Package  Previous  Next  Index