public class Insert
extends java.lang.Object
Insert
Java application illustrates an insertion sort.
Java Source Code for this class: http://www.cs.colorado.edu/~main/applications/Insert.java
Constructor and Description |
---|
Insert() |
Modifier and Type | Method and Description |
---|---|
static void |
insertionsort(int[] data,
int first,
int n)
Sort an array of integers from smallest to largest, using an insertion sort
algorithm.
|
static void |
main(java.lang.String[] args)
The main method illustrates the use of an insertion sort to sort a
small array.
|
public static void main(java.lang.String[] args)
args
- not used in this implementationpublic static void insertionsort(int[] data, int first, int n)
data
- the array to be sortedfirst
- the start index for the portion of the array that will be sortedn
- the number of elements to sort
Precondition:
data[first]
through data[first+n-1]
are valid
parts of the array.
Postcondition:
If n
is zero or negative then no work is done. Otherwise,
the elements of data
have been rearranged so that
data[first] <= data[first+1] <= ... <= data[first+n-1]
.java.lang.ArrayIndexOutOfBoundsException
- Indicates that first+n-1
is an index beyond the end of the
array.