Last Updated : 10 Apr, 2024

Predict the output for the below code snippet

set<int, greater<int>> dst;
dst.insert(20);
dst.insert(30);
dst.insert(10);
dst.insert(50);
dst.insert(10);
    
set<int> :: iterator itr;
for(itr = dst.begin(); itr != dst.end(); itr++)
  cout << *itr << \" \"; 

(A) 50 30 20 10 10
(B) 50 30 20 10
(C) 30 20 10 10 50
(D) None of these


Answer: (B)

Explanation: greater arranges the key is descending order.


Share your thoughts in the comments