Answers for "how to access a set in cpp"

C++
0

set in cpp

#include<iostream>
#include<set>
 
using namespace std;
 
int main(){
 
    // Set with values
    set<int, greater<int>> s1 = {6, 10, 5, 1};
    // s1 = {10, 6, 5, 1}
 
    // Inserting elements in the set
    s1.insert(12);
    s1.insert(20);
    s1.insert(3);
 
    // Iterator for the set
    set<int> :: iterator it;
 
    // Print the elements of the set
    for(it=s1.begin(); it != s1.end();it++)
        cout<<*it<<" ";
    cout<<endl;
 
}
Posted by: Guest on February-02-2021
0

set in cpp

#include<iostream>
#include<set>
 
using namespace std;
 
int main(){
 
    // Set with values
    set<int, greater<int>> s1 = {6, 10, 5, 1};
     
    // Iterator for the set
    set<int> :: iterator it;
 
    // Print the elements of the set
    for(it=s1.begin(); it != s1.end();it++)
        cout<<*it<<" ";
    cout<<endl;
}
Posted by: Guest on February-02-2021

Browse Popular Code Answers by Language