//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;
}
Input : set1{'a', 'b', 'c', 'd'};
set1.size();
Output : 4
Code Example |
---|
Cpp :: who made c++ |
Cpp :: while loop c++ |
Cpp :: string to wstring conversion c++ |
Cpp :: what do we use c++ vectors for |
Cpp :: equal elements in two arrays in c++ |
Cpp :: bus ticket booking online pakistan |
Cpp :: declaring multiple variables in cpp |
Cpp :: computer vision libraries c++ |
Cpp :: c++ pwstr to char* |
Cpp :: do while loop c++ |
C :: color text in C |
C :: unity change transparency script |
C :: c get time in milliseconds |
C :: wireless app debug android |
C :: octave dot operator |
C :: express.static public |
C :: data types in c |
C :: reverse integer in c |
C :: how to find sum of two nums |
C :: clrscr in c |
C :: c convert number to string |
C :: random float number in C |
C :: check if string in string c |
C :: c string |
C :: Gemfile.lock`. It is likely that you need to grant write permissions for that path. |
C :: C Passing Pointers to Functions |
C :: Fibonacci Series Program. in c |
C :: how to add 1 to 10 in c |
C :: how to malloc for matrix in c |
C :: multiplication of matrix in c |