Example input = [ 0 , 1 , 2 , 2 , 0 , 0 ] output = [ 0 , 0 , 0 , 1 , 2 , 2 ]
using System ; using System . Collections . Generic ; class GFG { static int [ ] inputArray = { 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 } ; static List < int > outputArray = new List < int > ( ) ; static int indexOfOne = 0 ; static void print ( ) { foreach ( int item in inputArray ) if ( item == 2 ) outputArray . Add ( item ) ; else if ( item == 1 ) { outputArray . Insert ( indexOfOne , item ) ; indexOfOne += 1 ; } else if ( item == 0 ) { outputArray . Insert ( 0 , item ) ; indexOfOne += 1 ; } else { Console . WriteLine ( " ▁ wrong ▁ value ▁ - ▁ Aborting ▁ " ) ; continue ; } } public static void Main ( String [ ] args ) { print ( ) ; foreach ( int item in outputArray ) Console . Write ( item + " , ▁ " ) ; } }