public static < E extends Comparable < E > > void sortDescending ( List < E > list ) { int index = 0 ; E value = null ; for ( int i = 1 ; i < list . size ( ) ; i ++ ) { index = i ; value = list . remove ( index ) ; while ( index > 0 && value . compareTo ( list . get ( index - 1 ) ) > 0 ) { list . add ( index , list . get ( index - 1 ) ) ; index -- ; } list . add ( index , value ) ; } }
Sort the list in descending 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 .