net.sf.jsort.sort
Class InsertSort

java.lang.Object
  extended by net.sf.jsort.sort.AbstractSort
      extended by net.sf.jsort.sort.InsertSort
All Implemented Interfaces:
CompareSort, SortAlgorithm

public final class InsertSort
extends AbstractSort

Implementation of the Insert sort algorithm.

The general idea of this algorithm is start with an already sorted array (the first element of the array).

The algorithm starts to insert a new element in the correct position (thus maintaining the array sorted), until the last element is inserted.

At worst case it will compare all element with all elements - letting the complexity O(n^2)

.

Author:
Domingos Creado
See Also:
http://en.wikipedia.org/wiki/Insertsort

Constructor Summary
InsertSort()
           
 
Method Summary
 void sort(java.lang.Object[] a, java.util.Comparator comparator, int start, int end)
          Sort a specific range of the list, using the specified comparator.
 
Methods inherited from class net.sf.jsort.sort.AbstractSort
sort, sort, sort, sort, sort, sort, sort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InsertSort

public InsertSort()
Method Detail

sort

public void sort(java.lang.Object[] a,
                 java.util.Comparator comparator,
                 int start,
                 int end)
Description copied from interface: CompareSort
Sort a specific range of the list, using the specified comparator.

Specified by:
sort in interface CompareSort
Specified by:
sort in class AbstractSort
Parameters:
a - to be sort


Copyright © 2005-2008 Domingos Creado. All Rights Reserved.