Stable sort for descending order | Bubble sort implementation to sort elements in descending order . ; Sorts a [ ] in descending order using bubble sort . ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void print ( List < int > a , int n ) { for ( int i = 0 ; i <= n ; i ++ ) Console . Write ( a [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } static void sort ( List < int > a , int n ) { for ( int i = n ; i >= 0 ; i -- ) for ( int j = n ; j > n - i ; j -- ) if ( a [ j ] > a [ j - 1 ] ) { int tempswap = a [ j ] ; a [ j ] = a [ j - 1 ] ; a [ j - 1 ] = tempswap ; } print ( a , n ) ; } static void Main ( ) { int n = 6 ; List < int > a = new List < int > ( ) ; a . Add ( 2 ) ; a . Add ( 4 ) ; a . Add ( 3 ) ; a . Add ( 2 ) ; a . Add ( 4 ) ; a . Add ( 5 ) ; a . Add ( 3 ) ; sort ( a , n ) ; } }