set in c++
C++
properties of a set c++#include <iostream>
#include <set>
#include <iterator>
using namespace std;
int main()
{
// empty set container
set <int, greater <int> > gquiz1;
// insert elements in random order
gquiz1.insert(40);
gquiz1.insert(30);
gquiz1.insert(60);
gquiz1.insert(20);
gquiz1.insert(50);
gquiz1.insert(50); // only one 50 will be added to the set
gquiz1.insert(10);
// printing set gquiz1
set <int, greater <int> > :: iterator itr;
cout << "\nThe set gquiz1 is : ";
for (itr = gquiz1.begin(); itr != gquiz1.end(); ++itr)
{
cout << '\t' << *itr;
}
cout << endl;
// assigning the elements from gquiz1 to gquiz2
set <int> gquiz2(gquiz1.begin(), gquiz1.end());
// print all elements of the set gquiz2
cout << "\nThe set gquiz2 after assign from gquiz1 is : ";
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr)
{
cout << '\t' << *itr;
}
cout << endl;
// remove all elements up to 30 in gquiz2
cout << "\ngquiz2 after removal of elements less than 30 : ";
gquiz2.erase(gquiz2.begin(), gquiz2.find(30));
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr)
{
cout << '\t' << *itr;
}
// remove element with value 50 in gquiz2
int num;
num = gquiz2.erase (50);
cout << "\ngquiz2.erase(50) : ";
cout << num << " removed \t" ;
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr)
{
cout << '\t' << *itr;
}
cout << endl;
//lower bound and upper bound for set gquiz1
cout << "gquiz1.lower_bound(40) : "
<< *gquiz1.lower_bound(40) << endl;
cout << "gquiz1.upper_bound(40) : "
<< *gquiz1.upper_bound(40) << endl;
//lower bound and upper bound for set gquiz2
cout << "gquiz2.lower_bound(40) : "
<< *gquiz2.lower_bound(40) << endl;
cout << "gquiz2.upper_bound(40) : "
<< *gquiz2.upper_bound(40) << endl;
return 0;
}
#include <set>
set<type> name; //set<int> s;// constructing sets
#include <iostream>
#include <set>
bool fncomp (int lhs, int rhs) {return lhs<rhs;}
struct classcomp {
bool operator() (const int& lhs, const int& rhs) const
{return lhs<rhs;}
};
int main ()
{
std::set<int> first; // empty set of ints
int myints[]= {10,20,30,40,50};
std::set<int> second (myints,myints+5); // range
std::set<int> third (second); // a copy of second
std::set<int> fourth (second.begin(), second.end()); // iterator ctor.
std::set<int,classcomp> fifth; // class as Compare
bool(*fn_pt)(int,int) = fncomp;
std::set<int,bool(*)(int,int)> sixth (fn_pt); // function pointer as Compare
return 0;
}
Also in C++:
- Title
- access last element in vector in c++
- Category
- C++
- Title
- c++ how to loop through a vector but not the last element
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- index string c++
- Category
- C++
- Title
- C++ If
- Category
- C++
- Title
- how to run a c++ program in the background
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- std::reverse
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- root to leaf path print
- Category
- C++
- Title
- c++ code 2d block
- Category
- C++
- Title
- merge sort in c++
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- c++ compiler for sublime text
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- length of string in c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- never gonna give you up lyrics
- Category
- C++
- Title
- empty string c++ value
- Category
- C++
- Title
- free or delete in c++
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- how to print nth palindrome number in c++
- Category
- C++
- Title
- binary tree deletion
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- how to pass an object by reference in c++
- Category
- C++
- Title
- sqrt in c++
- Category
- C++
- Title
- double ended queue in c++ stl
- Category
- C++
- Title
- cpp how to create an object of template class
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- how to delete an element in vector pair in cpp
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- filling 2d array with 0 c++
- Category
- C++
- Title
- Given an undirected graph, count the number of connected components.
- Category
- C++
- Title
- dfs in c++
- Category
- C++
- Title
- c++ while loop code
- Category
- C++
- Title
- least number of coins to form a sum
- Category
- C++
- Title
- lisy stl C++
- Category
- C++
- Title
- primeros numeors primos menores que
- Category
- C++
- Title
- std::iomanip c++
- Category
- C++
- Title
- cube mapping sdl
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- convert int to binary string c++
- Category
- C++
- Title
- how to open an input file in c++
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- cpp create lambda with recursion
- Category
- C++
- Title
- hashset in c++
- Category
- C++
- Title
- c++ vector pop_back
- Category
- C++
- Title
- pbds in c++
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- bfs in C++
- Category
- C++
- Title
- c++ code for polynomial addition
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- c++ convert int to double
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- c++ remove text file
- Category
- C++
- Title
- How to read a file in in C++
- Category
- C++
- Title
- when ratings will be updated for codechef
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- c++ give options string
- Category
- C++
- Title
- c++ program for matrix addition
- Category
- C++
- Title
- Find a element in a map C++
- Category
- C++
- Title
- calculate sum in c++
- Category
- C++
- Title
- c++ uint32_t
- Category
- C++
- Title
- C++ string format ctime
- Category
- C++
- Title
- char vector to string c++
- Category
- C++
- Title
- how to input multiple lines of a file in c++
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- c++ delete printed characters
- Category
- C++
- Title
- longest common subsequence
- Category
- C++
- Title
- how are graphics in games made
- Category
- C++
- Title
- E/flutter (20384): [ERROR:flutter/third_party/txt/src/minikin/FontFamily.cpp(184)] Could not get cmap table size! E/flutter (20384): F/flutter (20384): [FATAL:flutter/third_party/txt/src/minikin/FontCollection.cpp(95)] nTypefaces == 0
- Category
- C++
- Title
- lambda c++
- Category
- C++
- Title
- c++ overloaded equality check operator
- Category
- C++
- Title
- spicoli
- Category
- C++
- Title
- how to define a while statement in c++
- Category
- C++
- Title
- inserting an element in an set c++
- Category
- C++
- Title
- roscpp publish int32
- Category
- C++
- Title
- how to convert string to int c++
- Category
- C++
- Title
- accumulate c++ stl
- Category
- C++
- Title
- level order traversal
- Category
- C++
- Title
- string to vector c++
- Category
- C++
- Title
- arduino delay millis
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- error: invalid conversion from 'Node*' to 'int'
- Category
- C++
- Title
- hello world c++
- Category
- C++
- Title
- how to load from files C++
- Category
- C++
- Title
- c++ how to return an empty vector
- Category
- C++
- Title
- how to declare function with multiple parameter c++
- Category
- C++
- Title
- c++ function to find minimum element in array
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- iterate const vector
- Category
- C++
- Title
- sqrt cpp
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- matrix eigen c++ example
- Category
- C++
- Title
- ue4 c++ how to open a blueprint widget
- Category
- C++
- Title
- varint index
- Category
- C++