//try to copy the code to your compiler and run it to understand how it works
#include<iostream>
#include<set>
using namespace std;
int main(){
set<int>myset;
set<int>::iterator itbegin;
set<int>::reverse_iterator itend;
int n, val, i;
cout << "Enter n: ";
cin >> n;
cout << "Enter " << n << " values: ";
for (i = 0; i < n; i++){
cin >> val;
myset.insert(val);
}
cout << "Count of distinct values is " << myset.size() << endl;
itbegin = myset.begin();
cout << "Lowest value is " << *itbegin << endl;
itend = myset.rbegin();
cout << "Highest value is " << *itend << endl;
cout << "Distinct values entered in ascending order: ";
while (itbegin != myset.end()){
cout << *itbegin << " ";
itbegin++;
}
cout << endl;
cout << "Distinct values entered in descending order: ";
while (itend != myset.rend()){
cout << *itend << " ";
itend++;
}
cout << endl;
system("pause");
return 0;
}
set<int> setTemp {12,23,34,45,56,67};
int setLen = setTemp.size();
cout<<setLen<<endl;
// output: 6
Code Example |
---|
Cpp :: how to use a non const function from a const function |
Cpp :: c++ remove chars from string |
Cpp :: log base 2 in c++ |
Cpp :: system("pause") note working c++ |
Cpp :: c++ how to return an empty vector |
Cpp :: class operator overloading c++ |
Cpp :: how to add space in c++ |
Cpp :: heap buffer overflow in c |
Cpp :: c++ array pointer |
Cpp :: overload array operator cpp |
Cpp :: online ide c++ |
Cpp :: toString method in c++ using sstream |
Cpp :: c++ uint8_t header |
Cpp :: cpp gui |
Cpp :: QVariant to int |
Cpp :: array copx c++ |
Cpp :: how to traverse through vector pair |
Cpp :: rethrow exception c++ |
Cpp :: google test assert throw |
Cpp :: c++ call by value |
Cpp :: balanced brackets in c++ |
Cpp :: Arduino Real TIme Clock |
Cpp :: copy assignment operator in c++ |
Cpp :: c++ pointers and arrays |
Cpp :: c++ pass function as argument |
Cpp :: enum in c++ |
Cpp :: file streams in c++ |
Cpp :: double plus overload |
Cpp :: c++ read entire file into a variable |
Cpp :: C# adding numbers |