set c++
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;
}
properties of a set c++#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
- namespace c++
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- how do you add two random numbers in c++
- Category
- C++
- Title
- c++ initialization list
- Category
- C++
- Title
- best fit algorithm
- Category
- C++
- Title
- C++ string format ctime
- Category
- C++
- Title
- binary representation differ in bits
- Category
- C++
- Title
- getting a random letter in c++
- Category
- C++
- Title
- how to create object in c++
- Category
- C++
- Title
- Runtime Error: Runtime ErrorAbort signal from abort(3) (SIGABRT)
- Category
- C++
- Title
- calling by reference and pointers c++
- Category
- C++
- Title
- program to know if a number is prime
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- insert function in c++ vector
- Category
- C++
- Title
- how to delete a node c++
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- how to declare a function in c++
- Category
- C++
- Title
- c++ function return pointer to itself
- Category
- C++
- Title
- c++ read matttrix from text file
- Category
- C++
- Title
- declare vectors c++
- Category
- C++
- Title
- qt graphics scene map cursor position
- Category
- C++
- Title
- power in c++
- Category
- C++
- Title
- how to format decimal palces in c++
- Category
- C++
- Title
- container class in c++
- Category
- C++
- Title
- object slicing in c++
- Category
- C++
- Title
- runtime array size c++
- Category
- C++
- Title
- max element in array c++ stl
- Category
- C++
- Title
- iterate 2d array c++
- Category
- C++
- Title
- add a timer c++
- Category
- C++
- Title
- differentialble programming
- Category
- C++
- Title
- c++ triple
- Category
- C++
- Title
- uepic games github
- Category
- C++
- Title
- sum of two numbers c++
- Category
- C++
- Title
- shuffle vector c++
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- ue4 c++ struct
- Category
- C++
- Title
- how to sort a vector in reverse c++
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- iterative inorder traversal
- Category
- C++
- Title
- multiset c++
- Category
- C++
- Title
- how to iterate over unordered_map c++
- Category
- C++
- Title
- what is order in of preeendence in float, int, char, bool
- Category
- C++
- Title
- to_string c++
- Category
- C++
- Title
- Find the duplicate in an array of N integers.
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- select elements from array C++
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- basic ex of maps in c++
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- how to get a letter from the users string in c++
- Category
- C++
- Title
- sort a string alphabetically c++
- Category
- C++
- Title
- double to int c++
- Category
- C++
- Title
- mingw32/bin/ld.exe: C:\Users\mfrom\AppData\Local\Temp\ccSKcRks.o:PizzaPi.cpp:(.text$_ZN5PizzaC2Ev[__ZN5PizzaC2Ev]+0xa): undefined reference to `vtable for Pizza' collect2.exe: error: ld returned 1 exit status
- Category
- C++
- Title
- class is replace by structure
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- c++ scanf
- Category
- C++
- Title
- c++ vector pop_back
- Category
- C++
- Title
- sfml base program
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- how to find the size of a character array in c++
- Category
- C++
- Title
- two sum problem in c++
- Category
- C++
- Title
- c++ remove item from list
- Category
- C++
- Title
- log base e synthax c++
- Category
- C++
- Title
- arduino falling edge
- Category
- C++
- Title
- how to iterate through a map in c++
- Category
- C++
- Title
- knapsack
- Category
- C++
- Title
- how to use wasd c++
- Category
- C++
- Title
- c++ delete dynamically allocated array
- Category
- C++
- Title
- C++ int to char*
- Category
- C++
- Title
- stringstream in c++ with delimiter
- Category
- C++
- Title
- for loop
- Category
- C++
- Title
- c++ modulo make it give only positive numbers
- Category
- C++
- Title
- c++ for loop syntax
- Category
- C++
- Title
- create a dictionary cpp
- Category
- C++
- Title
- binary tree search
- Category
- C++
- Title
- Given an undirected graph, count the number of connected components.
- Category
- C++
- Title
- new c++
- Category
- C++
- Title
- for c++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- programa para saber si un numero es primo
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- how to convert number to string
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- how to sort a vector in c++
- Category
- C++
- Title
- length of 2d array c++
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- C++ w3schools
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- private and public in namespace cpp
- Category
- C++
- Title
- delete a double pointer c++
- Category
- C++
- Title
- create copy of range of string c++
- Category
- C++
- Title
- c++ yes no question
- Category
- C++
- Title
- find all the palindrome substring in a given string
- Category
- C++
- Title
- exponenciacion binaria
- Category
- C++
- Title
- coping 2d vector in cpp
- Category
- C++