Class InsertionSorter


public class InsertionSorter
extends ASorter
Inserts A[s] into A[lo:s-1], assuming A[lo;s-1] is sorted. Correponds to splitting the array at the high index, sort the two parts, and join the sorted part. The splitting is easy. It's the join that requires some work. As such, insertion sort is in the same family as merge sort.

Author:
Dung X. Nguyen - Copyright 1999 - all rights reserved.

Variable Index

 o Singleton

Constructor Index

 o InsertionSorter ()

Method Index

 o join (int[], int, int, int)
Inserts A[s] into the array A[lo:s-1], shifting elements of A to the right if necessary
 o main (String[])
A simple test case for InsertionSorter
 o split (int[], int, int)
Splits the array at the end (i

Variables

 o Singleton
public static final InsertionSorter Singleton

Constructors

 o InsertionSorter
private  InsertionSorter()

Methods

 o split
public int split(int[] A, int lo, int hi)
Splits the array at the end (i.e. high index).

Parameters:
A - array of integers.
lo - low index of A, < hi.
hi - high index of A, > lo.
Returns:
hi.
 o join
public void join(int[] A, int lo, int s, int hi)
Inserts A[s] into the array A[lo:s-1], shifting elements of A to the right if necessary.

Parameters:
A - A[lo:s-1], A[s:hi] are sorted
lo -
s - == hi.
hi -
 o main
public static void main(String[] args)
A simple test case for InsertionSorter.