Search
 
SCRIPT & CODE EXAMPLE
 

CPP

size() in c++ SET

//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;
}
Comment

set size in c++

set<int> setTemp {12,23,34,45,56,67};
int setLen = setTemp.size();
cout<<setLen<<endl;

// output:   6 
Comment

size of set c++

Input  : set1{'a', 'b', 'c', 'd'};
         set1.size();
Output : 4
Comment

PREVIOUS NEXT
Code Example
Cpp :: size of a matrix using vector c++ 
Cpp :: how to remove maximum number of characters in c++ cin,ignore 
Cpp :: c++ move semantics for `this` 
Cpp :: c++ write to csv file append 
Cpp :: array of struct in c++ 
Cpp :: map in c 
Cpp :: string format decimal places c++ 
Cpp :: hashmap c++ 
Cpp :: double array size c++ 
Cpp :: grep xargs sed 
Cpp :: prime or not in cpp 
Cpp :: calculator in cpp 
Cpp :: stl in c++ 
Cpp :: how to input in cpp 
Cpp :: how to check char array equality in C++ 
Cpp :: converting decimal to binary in cpp 
Cpp :: onoverlapbegin ue4 c++ 
Cpp :: for statement c++ 
Cpp :: what library is rand in c++ 
Cpp :: string concatenation operator overloading c++ 
Cpp :: move elements from vector to unordered_set 
Cpp :: c++ online compiler 
Cpp :: c++ include < vs "" 
Cpp :: C++ Nested if 
Cpp :: shift element to end of vector c++ 
Cpp :: copy vector c++ 
Cpp :: nth fibonacci number 
Cpp :: binary tree 
Cpp :: conversion of class type data into basic type data in c++ 
Cpp :: Consell de forces polítiques de Catalunya 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =