Utility function for insertion sort
static void insertionSort ( ArrayList < Integer > v , int n ) { int i , key , j ; for ( i = 1 ; i < n ; i ++ ) { key = v . get ( i ) ; j = i - 1 ; while ( j >= 0 && v . get ( j ) > key ) { v . set ( j + 1 , v . get ( i ) ) ; j = j - 1 ; } v . set ( j + 1 , key ) ; } }