Add elements in start to sort the array | Variation of Stalin Sort | C # implementation to sort the array by using the variation of the Stalin sort ; Function to sort the array ; Iterator < Integer > index = arr . iterator ( ) ; ; Driver Code ; Function call
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static void variationStalinsort ( List < int > arr ) { int j = 0 ; while ( true ) { int moved = 0 ; for ( int i = 0 ; i < ( arr . Count - 1 - j ) ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) { int index ; int temp ; index = arr [ i ] ; temp = arr [ i + 1 ] ; arr . Remove ( index ) ; arr . Insert ( i , temp ) ; arr . Remove ( temp ) ; arr . Insert ( i + 1 , index ) ; moved ++ ; } } j ++ ; if ( moved == 0 ) { break ; } } foreach ( int i in arr ) Console . Write ( i + " ▁ " ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 1 , 4 , 3 , 6 , 5 , 8 , 7 , 10 , 9 } ; List < int > arr1 = new List < int > ( ) ; for ( int i = 0 ; i < arr . Length ; i ++ ) arr1 . Add ( arr [ i ] ) ; variationStalinsort ( arr1 ) ; } }