Last active
December 29, 2015 07:59
-
-
Save abrarShariar/9386ee3483c0ac7a48a3 to your computer and use it in GitHub Desktop.
exploring <set> in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<set> | |
using namespace std; | |
int main(){ | |
//basic 101 | |
/* | |
set<int> numSet={1,2,3,4,5,454,999,91}; | |
for(auto it=numSet.begin();it!=numSet.end();it++){ | |
cout<<*it<<endl; | |
} | |
*/ | |
// basics 102 | |
/* | |
set<string> nameSet; | |
//input | |
for(int i=0;i<5;i++){ | |
string name; | |
cout<<"Name: "; | |
getline(cin,name); | |
nameSet.insert(name); | |
} | |
//prints | |
for(auto it=nameSet.begin();it!=nameSet.end();it++){ | |
cout<<*it<<endl; | |
} | |
*/ | |
//basic 103 | |
/* | |
set<string>preSet={"C++","Java","PHP"}; | |
set<string> nameSet(preSet.begin(),preSet.end()); | |
string num; | |
for(int i=0;i<5;i++){ | |
cout<<"Name["<<i<<"] : "; | |
cin>>num; | |
nameSet.insert(num); | |
} | |
for(auto it=nameSet.begin();it!=nameSet.end();it++){ | |
cout<<*it<<endl; | |
} | |
*/ | |
//basic 104 | |
//reverse iteration | |
//using reverse iterator on set | |
set<int>numSet; | |
for(int i=0;i<100;i++){ | |
numSet.insert(i+1); | |
} | |
for(auto it=numSet.rbegin();it!=numSet.rend();it++){ | |
cout<<*it<<" "; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment