sorts :: insertion sort


public class InsertionSort
{
  public static void main (String[] args)
  {
    int a[] = {53, 43, 63, 93, 103, 83, 13, 33, 23, 3, 73};
        
    insertion (a);
    
    // output sorted array
    for (int i = 0 ; i < a.length ; i++)
    {
      System.out.print (a [i] + " ");
    }    
    
  } // main method
  
  public static void insertion( int [ ] num)
  {
    int j; // the number of items sorted so far
    int key; // the item to be inserted
    int i;  
    
    // start with 1 (not 0)
    for (j = 1; j < num.length; j++) 
    {
      key = num[ j ];
      
      // smaller values are moving down 
      for(i = j - 1; (i >= 0) && (num[ i ] > key); i--) 
      {
        num[ i+1 ] = num[ i ];
      }
      
      // put the key in its proper location
      num[ i+1 ] = key; 
    }
  }// end of insertion method
} // Insertion Sort class

For a dynamic view of insertion click here