Saturday, 16 July 2011

Insertion Sort.


for ( i = 1 ; i <= 4 ; i++ )
 {
  for ( j = 0 ; j < i ; j++ )
  {
   if ( arr[j] > arr[i] )
   {
    temp = arr[j] ;
    arr[j] = arr[i] ;
    for ( k = i ; k > j ; k-- )
     arr[k] = arr[k - 1] ;
    arr[k + 1] = temp ;
   }
  }
 }

No comments:

Post a Comment