Last Updated :
10 Apr, 2024
set<int> st;
st.insert(20);
st.insert(30);
st.insert(10);
st.insert(50);
st.insert(10);
set<int> :: iterator itr;
for(itr = st.begin(); itr != st.end(); itr++)
cout << *itr << \" \";
Possible outcome of the above code snippet
(A) 10 10 20 30 50
(B) 50 30 20 10 10
(C) 10 20 30 50
(D) None of these
Answer: (C)
Explanation: Keys in the set arranged in natural order. Similar to unordered_set as no duplicates are allowed.
Share your thoughts in the comments
Please Login to comment...