Taking in the input and initializing the set STL set in cpp has a property that it maintains the elements in sorted order , thus we do not need to sort them externally
int n = 3 ; int [ ] input = new int [ ] { 2 , 5 , 6 , 7 , 11 } ; HashSet < int > GCD = new HashSet < int > ( input ) ; List < int > arr = new List < int > ( ) ; foreach ( int b in GCD ) arr . Add ( b ) ;