public static < E extends Comparable < E > > void sort ( List < E > list ) { boolean swapped = true ; while ( swapped ) { swapped = false ; for ( int i = 0 ; i < ( list . size ( ) - 1 ) ; i ++ ) { if ( list . get ( i ) . compareTo ( list . get ( i + 1 ) ) > 0 ) { TrivialSwap . swap ( list , i , i + 1 ) ; swapped = true ; } } } }
Sort the list in ascending order using this algorithm . The run time of this algorithm depends on the implementation of the list since it has elements added and removed from it .