text: Print n smallest elements from given array in their original order | C # for printing smallest n number in order ; Function to print smallest n numbers ; Make copy of array ; Sort copy array ; For each arr [ i ] find whether it is a part of n - smallest with binary search ; Driver code
code: using System ; class GFG { static void printSmall ( int [ ] arr , int asize , int n ) { int [ ] copy_arr = new int [ asize ] ; Array . Copy ( arr , copy_arr , asize ) ; Array . Sort ( copy_arr ) ; for ( int i = 0 ; i < asize ; ++ i ) { if ( Array . BinarySearch ( copy_arr , 0 , n , arr [ i ] ) > - 1 ) Console . Write ( arr [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 } ; int asize = arr . Length ; int n = 5 ; printSmall ( arr , asize , n ) ; } }