org.amino.alg.sort
Class InsertionSorter

java.lang.Object
  extended by org.amino.alg.sort.AbstractSorter
      extended by org.amino.alg.sort.DefaultSorter
          extended by org.amino.alg.sort.InsertionSorter
All Implemented Interfaces:
Sorter

public class InsertionSorter
extends DefaultSorter

This class implements the basic Insertion sorting algorithm. Insertion sort is a simple comparison sorting algorithm that can be used for small lists of data. It is efficient for small sets of data. For larger lists more efficient algorithms like quicksort, heapsort etc. should be used.


Constructor Summary
InsertionSorter()
           
 
Method Summary
 void reverse(byte[] a, int from, int to)
          Sort array using reverse natural (descending) order.
 void reverse(char[] a, int from, int to)
          Sort array using reverse natural (descending) order.
 void reverse(double[] a, int from, int to)
          Sort array using reverse natural (descending) order.
 void reverse(float[] a, int from, int to)
          Sort array using reverse natural (descending) order.
 void reverse(int[] a, int from, int to)
          Sort array using reverse natural (descending) order.
 void reverse(long[] a, int from, int to)
          Sort array using reverse natural (descending) order.
 void reverse(short[] a, int from, int to)
          Sort array using reverse natural (descending) order.
 void sort(byte[] a, int from, int to)
           
 void sort(char[] a, int from, int to)
           
 void sort(double[] a, int from, int to)
           
 void sort(float[] a, int from, int to)
           
 void sort(int[] a, int from, int to)
           
 void sort(long[] a, int from, int to)
           
 void sort(short[] a, int from, int to)
           
 
Methods inherited from class org.amino.alg.sort.DefaultSorter
reverse, reverse, sort, sort, sort, sort, sort, sort, sortp
 
Methods inherited from class org.amino.alg.sort.AbstractSorter
reverse, reverse, reverse, reverse, reverse, reverse, reverse, reverse, reverse, sort, sort, sort, sort, sort, sort, sort, sort, sort, swap, swap, swap, swap, swap, swap, swap, swap, swapIfGreater, swapIfGreater, swapIfGreater, swapIfGreater, swapIfGreater, swapIfGreater, swapIfGreater, swapIfGreater, swapIfLess, swapIfLess, swapIfLess, swapIfLess, swapIfLess, swapIfLess, swapIfLess, swapIfLess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InsertionSorter

public InsertionSorter()
Method Detail

sort

public void sort(byte[] a,
                 int from,
                 int to)
Specified by:
sort in interface Sorter
Overrides:
sort in class DefaultSorter
Parameters:
a - is the byte array to be sorted in an ascending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted
See Also:
Arrays.sort(byte[], int, int)

reverse

public void reverse(byte[] a,
                    int from,
                    int to)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Overrides:
reverse in class DefaultSorter
Parameters:
a - is the byte array to be sorted in a descending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted

sort

public void sort(char[] a,
                 int from,
                 int to)
Specified by:
sort in interface Sorter
Overrides:
sort in class DefaultSorter
Parameters:
a - is the character array to be sorted in an ascending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted
See Also:
Arrays.sort(byte[], int, int)

reverse

public void reverse(char[] a,
                    int from,
                    int to)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Overrides:
reverse in class DefaultSorter
Parameters:
a - is the character array to be sorted in a descending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted

sort

public void sort(short[] a,
                 int from,
                 int to)
Specified by:
sort in interface Sorter
Overrides:
sort in class DefaultSorter
Parameters:
a - is the short array to be sorted in an ascending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted
See Also:
Arrays.sort(short[], int, int)

reverse

public void reverse(short[] a,
                    int from,
                    int to)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Overrides:
reverse in class DefaultSorter
Parameters:
a - is the short array to be sorted in a descending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted

sort

public void sort(int[] a,
                 int from,
                 int to)
Specified by:
sort in interface Sorter
Overrides:
sort in class DefaultSorter
Parameters:
a - is the int array to be sorted in an ascending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted
See Also:
Arrays.sort(short[], int, int)

reverse

public void reverse(int[] a,
                    int from,
                    int to)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Overrides:
reverse in class DefaultSorter
Parameters:
a - is the int array to be sorted in a descending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted

sort

public void sort(long[] a,
                 int from,
                 int to)
Specified by:
sort in interface Sorter
Overrides:
sort in class DefaultSorter
Parameters:
a - is the long array to be sorted in an ascending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted
See Also:
Arrays.sort(short[], int, int)

reverse

public void reverse(long[] a,
                    int from,
                    int to)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Overrides:
reverse in class DefaultSorter
Parameters:
a - is the long array to be sorted in a descending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted

sort

public void sort(float[] a,
                 int from,
                 int to)
Specified by:
sort in interface Sorter
Overrides:
sort in class DefaultSorter
Parameters:
a - is the float array to be sorted in an ascending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted
See Also:
Arrays.sort(short[], int, int)

reverse

public void reverse(float[] a,
                    int from,
                    int to)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Overrides:
reverse in class DefaultSorter
Parameters:
a - is the float array to be sorted in a descending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted

sort

public void sort(double[] a,
                 int from,
                 int to)
Specified by:
sort in interface Sorter
Overrides:
sort in class DefaultSorter
Parameters:
a - is the double array to be sorted in an ascending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted
See Also:
Arrays.sort(short[], int, int)

reverse

public void reverse(double[] a,
                    int from,
                    int to)
Description copied from interface: Sorter
Sort array using reverse natural (descending) order.

Specified by:
reverse in interface Sorter
Overrides:
reverse in class DefaultSorter
Parameters:
a - is the double array to be sorted in a descending order using Insertion Sort algorithm
from - is the start index of array to be sorted
to - is the end index of array to be sorted


Copyright © 2008. All Rights Reserved.