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 [ ] = { 2 , 5 , 6 , 7 , 11 } ; set < int > GCD ( input , input + n ) ; vector < int > arr ; set < int > :: iterator it ; for ( it = GCD . begin ( ) ; it != GCD . end ( ) ; ++ it ) arr . push_back ( * it ) ;