Vous êtes sur la page 1sur 13

<algorithms> library in C++ STL

Non-modifying sequence operations


1. std :: all_of : Test condition on all elements in range
2. std :: any_of : Test if any element in range fulfills condition
3. std :: none_of : Test if no elements fulfill condition
4. std :: for_each : Apply function to range
5. std :: find : Find value in range
6. std :: find_if : Find element in range
7. std :: find_if_not : Find element in range (negative condition)
8. std :: find_end : Find last subsequence in range
9. std :: find_first_of : Find element from set in range
10. std :: adjacent_find : Find equal adjacent elements in range
11. std :: count : Count appearances of value in range
12. std :: count_if : Return number of elements in range satisfying condition
13. std :: mismatch : Return first position where two ranges differ
14. std::equal : Test whether the elements in two ranges are equal
15. std :: is_permutation : Test whether range is permutation of another
16. std :: search : Search range for subsequence
17. std :: search_n : Search range for element
Modifying sequence operations
1. std :: copy : Copy range of elements
2. std :: copy_n : Copy elements
3. std :: copy_if : Copy certain elements of range
4. std :: copy_backward : Copy range of elements backward
5. std::move : Move range of elements
6. std :: move_backward : Move range of elements backward
7. std :: swap : Exchange values of two objects
8. std ::swap_ranges : Exchange values of two ranges
9. std :: iter_swap : Exchange values of objects pointed to by two iterators
10. std ::transform : Transform range
11. std ::replace : Replace value in range
12. std ::replace_if : Replace values in range
13. std :: replace_copy : Copy range replacing value
14. std :: replace_copy_if : Copy range replacing value
15. std ::fill : Fill range with value
16. std :: fill_n : Fill sequence with value
17. std ::generate : Generate values for range with function
18. std ::generate_n : Generate values for sequence with function
19. std ::remove : Remove value from range
20. std :: remove_if : Remove elements from range
21. remove_copy : Copy range removing value
22. remove_copy_if : Copy range removing values
23. std ::unique : Remove consecutive duplicates in range
24. std :: unique_copy : Copy range removing duplicates
25. std ::reverse : Reverse range
26. std :: reverse_copy : Copy range reversed
27. std :: rotate : Rotate left the elements in range
28. std :: rotate_copy : Copy range rotated left
29. std :: random_shuffle : Randomly rearrange elements in range
30. std :: shuffle : Randomly rearrange elements in range using generator
Partition Operations
1. std :: is_partitioned : Test whether range is partitioned
2. std :: partition : Partition range in two
3. std :: stable_partition : Partition range in two – stable ordering
4. partition_copy : Partition range into two
5. partition_point : Get partition point
Sorting
1. std :: sort : Sort elements in range
2. std :: stable_sort : Sort elements preserving order of equivalents
3. std :: partial_sort : Partially sort elements in range
4. std :: partial_sort_copy : Copy and partially sort range
5. std :: is_sorted : Check whether range is sorted
6. std :: is_sorted_until : Find first unsorted element in range
7. std :: nth_element : Sort element in range
Binary search (operating on partitioned/sorted ranges)
1. std :: lower_bound : Return iterator to lower bound
2. std :: upper_bound : Return iterator to upper bound
3. std :: equal_range : Get subrange of equal elements
4. std :: binary_search : Test if value exists in sorted sequence
Merge (operating on sorted ranges)
1. std :: merge : Merge sorted ranges
2. std :: inplace_merge : Merge consecutive sorted ranges
3. std :: includes : Test whether sorted range includes another sorted range
4. std :: set_union : Union of two sorted ranges
5. std :: set_intersection : Intersection of two sorted ranges
6. std :: set_difference : Difference of two sorted ranges
7. std :: set_symmetric_difference : Symmetric difference of two sorted ranges
Heap Operations
1. std :: push_heap : Push element into heap range
2. std :: pop_heap : Pop element from heap range
3. std :: make_heap : Make heap from range
4. std :: sort_heap : Sort elements of heap
5. std :: is_heap : Test if range is heap
6. std :: is_heap_until : Find first element not in heap order
7. std :: max : Return the largest
8. std :: minmax : Return smallest and largest elements
9. std :: min_element : Return smallest element in range
10. std :: max_element : Return largest element in range
11. std :: minmax_element : Return smallest and largest elements in range
Other Operations
1. std :: lexicographical_compare : Lexicographical less-than comparison
2. std :: next_permutation : Transform range to next permutation
3. std :: prev_permutation : Transform range to previous permutation

Vector in C++ STL


Iterators
1. vector_name.begin() – Returns an iterator pointing to the first element in the vector
2. vector_name.end() – Returns an iterator pointing to the theoretical element that
follows the last element in the vector
3. vector_name.rbegin() – Returns a reverse iterator pointing to the last element in
the vector (reverse beginning). It moves from last to first element
4. vector_name.rend() – Returns a reverse iterator pointing to the theoretical element
preceding the first element in the vector (considered as reverse end)
5. vector_name.cbegin() – Returns a constant iterator pointing to the first element in
the vector.
6. vector_name.cend() – Returns a constant iterator pointing to the theoretical
element that follows the last element in the vector.
7. vector_name.crbegin() – Returns a constant reverse iterator pointing to the last
element in the vector (reverse beginning). It moves from last to first element
8. vector_name.crend() – Returns a constant reverse iterator pointing to the
theoretical element preceding the first element in the vector (considered as reverse
end)
Capacity
1. vector_name.size() – Returns the number of elements in the vector.
2. vector_name.max_size() – Returns the maximum number of elements that the
vector can hold.
3. vector_name.capacity() – Returns the size of the storage space currently allocated
to the vector expressed as number of elements.
4. vector_name.resize(g) – Resizes the container so that it contains ‘g’ elements.
5. vector_name.empty() – Returns whether the container is empty.
6. vector_name.shrink_to_fit() – Reduces the capacity of the container to fit its size
and destroys all elements beyond the capacity.
7. vector_name.reserve(n) – Requests that the vector capacity be at least enough to
contain n elements.
Element access:
1. vector_name.reference operator [g] – Returns a reference to the element at
position ‘g’ in the vector
2. vector_name.at(g) – Returns a reference to the element at position ‘g’ in the vector
3. vector_name.front() – Returns a reference to the first element in the vector
4. vector_name.back() – Returns a reference to the last element in the vector
5. vector_name.data() – Returns a direct pointer to the memory array used internally
by the vector to store its owned elements. Ex: int* pos = g1.data();
cout << "\nThe first element is " << *pos;
Modifiers:
1. vector_name.assign( num_of _time, value_to_be_assigned) – It assigns new value
to the vector elements by replacing old ones
2. vector_name.push_back(x) – It push the elements into a vector from the back
3. vector_name.pop_back() – It is used to pop or remove elements from a vector from
the back.
4. vector_name.insert( specified_position, value_to_be_insert) – It inserts new
elements before the element at the specified position
5. vector_name.erase() – It is used to remove elements from a container from the
specified position or range.
vectorname.clear()-used to remove all the elements of the vector container, thus
making it size 0.
vectorname.erase(position)-
vectorname.erase(startingposition, endingposition)-
used to remove elements from a container from the specified position or range.
6. vector_name1.swap (vectorname2_with which to be swap) – It is used to swap the
contents of one vector with another vector of same type. Sizes may differ.
7. vector_name.clear() – It is used to remove all the elements of the vector container
8. vector_name.emplace() – It extends the container by inserting new element at
position
Parameter:
The function accepts two mandatory parameters which are specified as below:
 position – It specifies the iterator pointing to the position in the container where the new element is
to be inserted.
 args – It specifies the element to be inserted to be inserted in the vector container.
Return value:
The function returns an iterator which points to the newly inserted element.
9. vector_name.emplace_back(value) – It is used to insert a new element into the
vector container, the new element is added to the end of the vector

List in C++ Standard Template Library (STL)


 list_name.front() – Returns the value of the first element in the list.
 list_name.back() – Returns the value of the last element in the list .
 list_name.push_front(g) – Adds a new element ‘g’ at the beginning of the list .
 list_name.push_back(g) – Adds a new element ‘g’ at the end of the list.
 list_name.pop_front() – Removes the first element of the list, and reduces size of the list
by 1.
 list_name.pop_back() – Removes the last element of the list, and reduces size of the list
by 1
 list_name.begin() and list_name.end() in C++ STL– begin() function returns an iterator
pointing to the first element of the list
 list_name.end()– end() function returns an iterator pointing to the theoretical last element
which follows the last element.
used to get an iterator to past the last element. By past the last element it is meant that the
iterator returned by the end() function return an iterator to an element which follows the last element
in the list container. It can not be used to modify the element or the list container.
 list_name.rbegin() and list_name.rend() function in C++ STL– rbegin() returns a reverse
iterator which points to the last element of the list. rend() returns a reverse iterator which
points to the position before the beginning of the list.
 list cbegin() and cend() function in C++ STL– cbegin() returns a constant random access
iterator which points to the beginning of the list. cend()returns a constant random access
iterator which points to the end of the list.
 list crbegin() and crend() function in C++ STL– crbegin() returns a constant reverse
iterator which points to the last element of the list i.e reversed beginning of
container. crend() returns a constant reverse iterator which points to the theoretical
element preceding the first element in the list i.e. the reverse end of the list.
 list_name.empty() – Returns whether the list is empty(1) or not(0).
 list_name.insert(pos_iter,ele_num,ele) – Inserts new elements in the list before the
element at a specified position.
Parameters: This function takes in three parameters:
-pos_iter: Position in the container where the new elements are inserted.
-ele_num: Number of elements to insert. Each element is initialized to a copy
of val.
-ele: Value to be copied (or moved) to the inserted elements.
Return Value: This function returns an iterator that points to the first of the newly
inserted elements.

 list_name.erase(iterator position) -
list_name.erase(iterator fis, iterator last) – Removes a single element or a range of
elements from the list.
Parameters: This function can accepts different parameters based on whether it is used to erase
a single element or a range of element from the list container.
-position: This parameter is used when the function is used to delete a single element.
This parameter refers to an iterator which points to the element which is need to be erased from
the list container.
-first, last: These two parameters are used when the list is used to erase elements from
a range. The parameter first refers to the iterator pointing to the first element in the range and the
parameter last refers to the iterator pointing to the last element in the range which is needed to be
erased. This erases all the elements in the range including the element pointed by the
iterator first but excluding the element pointed by the iterator last.
Return Value: This function returns an iterator pointing to the element in the list container which
followed the last element erased from the list container.

 list_name.assign(count,value) – Assigns new elements to list by replacing current


elements and resizes the list.
Parameters: This function accepts two mandatory parameters as shown in the above syntax and
described below:
-count: The number of values needed to be assigned to the list with name list_name.
-value: This is the value that will be assigned count number of times starting from the first
element. If the list already contains some elements then those elements will be replaced by
the element specified in the parameter value. The data type of this parameter must be of
the same type as that of list_name.
Return Value: This function assigns the element specified in the valueparameter count number
of times starting from the first element in the list list_name. The return type of this function is void
and it does not returns any value.

To copy elements from an existing list to a new list.


Syntax: first_list.assign(second_list.begin(), second_list.end());
Parameters: This function accepts two parameter as shown in the above syntax. The first
parameter is the beginning iterator of the second list and second parameter is the ending iterator
of the second list.
Return Value: This function copies the second_list to first_list. This function does not returns any
value.

 list_name.remove(val) – Removes all the elements from the list, which are equal to given
element.
 list_name.remove_if(predicate) in C++ STL– Used to remove all the values from the list
that correspond true to the predicate or condition given as parameter to the function.
The predicate in the form of aa function pointer or function object is passed
as the parameter.

 list_name.reverse() – Reverses the list.(does not return anyrhing).


 list_name.size() – Returns the number of elements in the list.
 list_name.resize()function in C++ STL– Used to resize a list container.
 list_name.sort() – Sorts the list in increasing order. { Time Complexity : O(nlogn)}
 list_name.max_size() function in C++ STL– Returns the maximum number of elements a
list container can hold.
 list_name.unique() in C++ STL– Removes all duplicate consecutive elements from the list.
 list_name.emplace_front(value) and list_name.emplace_back(value) in C++
STL– emplace_front()function is used to insert a new element into the list container, the
new element is added to the beginning of the list. emplace_back() function is used to
insert a new element into the list container, the new element is added to the end of the list.
 list_name.clear() in C++ STL– clear() function is used to remove all the elements of the list
container, thus making it size 0.
 list::operator= in C++ STL– This operator is used to assign new contents to the container
by replacing the existing contents.
Syntax :
listname1 = (listname2)
 list_name.swap() in C++ STL– This function is used to swap the contents of one list with
another list of same type and size.
Syntax :
listname1.swap(listname2)

 list_name.splice() function in C++ STL– Used to transfer elements from one list to
another.
 list_name.merge() function in C++ STL– Merges two sorted lists into one
Syntax:
list1_name.merge(list2_name)
Syntax:
list1_name.merge(list2_name, comparator)
Parameters: The function accepts two parameters which are described below:
list2-name – It specifies the list2 which is to be merged in list1.
comparator – It is a binary predicate which takes two values of the same type that of those
contained in the list, returns true if the first argument is considered to go before the second in the
strict weak ordering it defines, and false otherwise.
 list_name.emplace(iterator point to the target position, element) function in C++ STL–
Extends list by inserting new element at a given position.
Return value: It returns a random access iterator which points to the newly inserted element.
Forward List in C++
1. assign() :- This function is used to assign values to forward list, its another variant is used to
assign repeated elements.

Syntax:
Version 1:forward_list_name.assign(iterator it1, iterator it2)
Version 2:forward_list_name.assign(int n, val)
Version 3:forward_list_name.assign(initializer_list li)
Parameters: This function accepts different parameters in different version which are
discussed below:
 Iterator: The first version takes two iterators as parameters. New elements are
constructed from each element in the range [it1, it2) i.e it includes all elements
between it1 and it2 including the element dereferenced by it1 but excluding the
element pointed by it2.
 n and val: In the second version n elements are created and each element is
initialized with value val.
 Ininitializer_list: In the third version the new contents are created which are
initialized with copies of the values passed as initializer list, in the same order.
Return Value This function does not return any value.

2. push_front ( val ) :- This function is used to insert the element at the first position on forward
list. The value from this function is copied to the space before first element in the container. The
size of forward list increases by 1.
3. pop_front() :- This function is used to delete the first element of list.
4. emplace_front ( val ) :- This function is similar to the previous function but in this no copying
operation occurs, the element is created directly at the memory before the first element of the
forward list. Time Complexity : O(1)
4. insert_after (iterator position, vals ) This function gives us a choice to insert elements at
any position in forward list. The arguments in this function are copied at the desired position.
5. emplace_after ( iterator position, elenments ) This function also does the same operation
as above function but the elements are directly made without any copy operation. This function
returns an iterator that points to the newly inserted element.
6. erase_after() This function is used to erase elements from a particular position in the forward
list. Clear() - used to remove all the elements of the forward list container, thus making its size 0.

Syntax :
1. flistname.erase_after(position)
2. flistname.erase_after(startingposition, endingposition)
Parameters :
Position previous of the element to be removed in the form of iterator.
or the range specified using start and end iterator.
Result :
Elements are removed from the next position of the container.
7. remove ( element ) :- This function removes the particular element from the forward
list mentioned in its argument.
8. remove_if (predicate) :- This function removes according to the condition in its
argument.
9. splice_after() :- This function transfers elements from one forward list to other.

Syntax:
forwardlist1_name.splice_after(position iterator, forwardlist2_name,
first iterator, last iterator)
Parameters: The function accepts four parameters which are specified as below:
 position – Specifies the position in the forward_list after which the new elements
are to be inserted.
 forwardlist2_name– Specifies the list from which elements are to be inserted.
 first– Specifies the iterator after which insertion is to be done.
 last– Specifies the iterator till which insertion is to be done.
Return value: The function has no return value.

10. front()– This function is used to reference the first element of the forward list container.
 begin()– begin() function is used to return an iterator pointing to the first element of the
forward list container.
 end()– end() function is used to return an iterator pointing to the last element of the list
container.
 cbegin()– Returns a constant iterator pointing to the first element of the forward_list.
 cend()– Returns a constant iterator pointing to the past-the-last element of the forward_list.
 before_begin()– Returns a iterator which points to the position before the first element of
the forward_list.
 cbefore_begin()– Returns a constant random access iterator which points to the position
before the first element of the forward_list.
 max_size()– Returns the maximum number of elements can be held by forward_list.
18. resize()– Changes the size of forward_list.
19. merge() :- This function is used to merge one forward list with other. If both the lists are
sorted then the resulted list returned is also sorted.
Syntax:
forwardlist_name1.merge(forward_list& forwardlist_name2)
or
forwardlist_name1.merge(forward_list& forwardlist_name2, Compare comp)
Parameters: The function accepts two parameters which are specified as below:
1. forwardlist_name2 – Another forward list of the same type which is to be merged
2. comp – A comparison function which should return true or false.
Return value: The function does not return anything.
20. operator “=” :- This operator copies one forward list into other. The copy made in this case
is deep copy.
Syntax: forwardlistname1 = (forwardlistname2)
21. sort() :- This function is used to sort the forward list.
Time Complexity : O(nlogn)
22. unique() :- This function deletes the multiple occurrences of a number and returns a forward
list with unique elements. The forward list should be sorted for this function to execute
successfully.

23. reverse() :- This function is used to reverse the forward list.


24. swap() :- This function swaps the content of one forward list with other.
Syntax : forwardlistname1.swap(forwardlistname2)
25. empty() :- This function returns true if the list is empty otherwise false

Array class in C++


How to decleare: Ex: array<int,6> ar = {1, 2, 3, 4, 5, 6};

1. array name.at() :- This function is used to access the elements of array.


2. get() :- This function is also used to access the elements of array. This function is not the
member of array class but overloaded function from class tuple.
3. operator[] :- This is similar to C-style arrays. This method is also used to access array
elements.
4. array name.front() :- This returns the first element of array.
5. array name.back() :- This returns the last element of array.
6. array name.size() :- It returns the number of elements in array. This is a property that C-style
arrays lack.
7. array name.max_size() :- It returns the maximum number of elements array can hold i.e, the
size with which array is declared. The size() and max_size() return the same value.
8. array1 name.swap (array2 name) :- The swap() swaps all elements of one array with other.
9. empty() :- This function returns true when the array size is zero else returns false.
10. fill (val) :- This function is used to fill the entire array with a particular value.

Deque in C++ Standard Template Library (STL)


How to decleare: Ex: deque <int> gquiz;

Methods of Deque:
 deque insert() function in C++ STL: Returns an iterator that points to the first of the newly
inserted elements.
Syntax:
deque_name.insert (iterator position, const value_type& val)
or
deque_name.insert (iterator position, size_type n, const value_type& val)
or
deque_name.insert (iterator position, InputIterator first, InputIterator last)
Parameters: The function accepts four parameters which are specified as below:
position – Specifies the position where the element/elements are to be inserted.
val – specifies the value to be assigned to newly inserted element.
n – specifies the number of elements to insert. Each element is initialized to a copy of val.
first, last – specifies the iterators specifying a range of elements which is to be inserted. The range
includes all the elements between first and last, including the element pointed by first but not the
one pointed by last.

 deque rbegin() function in C++ STL: Returns a reverse iterator which points to the last
element of the deque (i.e., its reverse beginning).
 deque rend() function in C++ STL: Returns a reverse iterator which points to the position
before the beginning of the deque (which is considered its reverse end).
 deque cbegin() in C++ STL: Returns a constant iterator pointing to the first element of the
container, that is, the iterator cannot be used to modify, only traverse the deque.
 deque max_size() function in C++ STL: Returns the maximum number of elements that a
deque container can hold.
 deque assign() function in C++ STL: Assign values to the same or different deque
container.
1. Syntax:
deque_name.assign(size, val)
Parameters: The function accepts two parameters which are described below:
 size: it specifies the number of values to be assigned to the container.
 val: it specifies the value to be assigned to the container.
Return Value: The function returns nothing.
2. Syntax:
deque1_name.assign(iterator1, iterator2)
Parameters: The function accepts two parameters which are described below:
 iterator1: it specifies the iterator which points to the starting element of container(deque, array, …)
whose elements are to be transferred to deque1.
 iterator2: it specifies the iterator which points to the last element of a container(deque, array, …)
whose elements are to be transferred to deque1
Return Value: The function returns nothing.
 deque resize (n) function in C++ STL: Function which changes the size of the deque to n.
 deque::push_front (val) in C++ STL: This function is used to push elements into a deque
from the front.
 deque::push_back (val) in C++ STL: This function is used to push elements into a deque
from the back.
 deque::pop_front() and deque::pop_back() in C++ STL: pop_front() function is used to
pop or remove elements from a deque from the front. pop_back()function is used to pop
or remove elements from a deque from the back.
 deque::front() and deque::back() in C++ STL: front() function is used to reference the first
element of the deque container. back() function is used to reference the last element of
the deque container.
 deque::clear() and deque::erase() in C++ STL: clear() function is used to remove all the
elements of the deque container, thus making its size 0.
 dequename.erase() function is used to remove elements from a container from the
specified position or range.
Syntax :
1. dequename.erase(position)
2. dequename.erase(startingposition, endingposition)
Parameters :
Position of the element to be removed in the form of iterator.
or the range specified using start and end iterator.

 deque::empty() and deque::size() in C++ STL: empty() function is used to check if the
deque container is empty or not. size() function is used to return the size of the deque
container or the number of elements in the deque container.
 deque::operator= and deque::operator[] in C++ STL:
operator= operator is used to assign new contents to the container by replacing the
existing contents. dequename1 = (dequename2);
 operator[] operator is used to reference the element present at position given inside the
operator. dequename[position];
 deque::at() and deque::swap() in C++ STL: at() function is used reference the element
present at the position given as the parameter to the function.
dequename.at(position);
 swap() function is used to swap the contents of one deque with another deque of same
type and size. dequename1.swap(dequename2);
 deque::begin() and deque::end in C++ STL: begin() function is used to return an iterator
pointing to the first element of the deque container. end()function is used to return an
iterator pointing to the last element of the deque container.
 deque::emplace_front (val) and deque::emplace_back (val) in C++
STL: emplace_front() function is used to insert a new element into the deque container.
The new element is added to the beginning of the deque. emplace_back() function is
used to insert a new element into the deque container. The new element is added to the
end of the deque.

Set in C++ Standard Template Library (STL)


Methods of set:
 setname.begin() – Returns an iterator to the first element in the set.
 setname.end() – Returns an iterator to the theoretical element that follows last element in
the set.
 setname.rbegin()– Returns a reverse iterator pointing to the last element in the container.
 setname.rend()– Returns a reverse iterator pointing to the theoretical element right before
the first element in the set container.
 setname.crbegin()– Returns a constant iterator pointing to the last element in the
container.
 setname.crend() – Returns a constant iterator pointing to the position just before the first
element in the container.
 setname.cbegin()– Returns a constant iterator pointing to the first element in the container.
 setname.cend() – Returns a constant iterator pointing to the position past the last element
in the container.
 setname.size() – Returns the number of elements in the set.
 setname.max_size() – Returns the maximum number of elements that the set can hold.
 setname.empty() – Returns whether the set is empty.
 setname.insert(const g) – Adds a new element ‘g’ to the set.
1.Syntax:
iterator set_name.insert(element)
Parameters: The function accepts a mandatory parameter element which is to be inserted in the
set container.
Return Value: The function returns an iterator pointing to the inserted element in the container.
2.Syntax:
iterator set_name.insert(iterator position, element)
Parameters: The function accepts two parameter which are described below:
 element: It specifies the element to be inserted in the set container.
 position: It does not specify the position where the insertion is to be done, it only points to a
position from where the searching operation is to be started for insertion to make the process
faster. The insertion is done according to the order which is followed by the set container.
Return Value: The function returns an iterator pointing to the inserted element in the container.
3.Syntax:
iterator set_name.insert(iterator position1, iterator position2)
Parameters: The function accepts two parameters position1 and position2which specifies the range of
elements. All the elements in the range [position1, last) are inserted in another set container.
Return Value: The function returns a set which has all the elements in range [position1, last).

 setname.erase(iterator position) – Removes the element at the position pointed by the


iterator.
Syntax :
1. setname.erase(position)
2. setname.erase(startingposition, endingposition)
Parameters :
Position of the element to be removed in
the form of iterator or the range specified
using start and end iterator.
Result :
Elements are removed from the specified
position of the container.

 setname.erase(const g)– Removes the value ‘g’ from the set.


 setname.clear() – Removes all the elements from the set.
 key_comp() / value_comp() – Returns the object that determines how the elements in the
set are ordered (‘<‘ by default).
 setname.find(const g) – Returns an iterator to the element ‘g’ in the set if found, else
returns the iterator to end.
 setname.count(const g) – Returns 1 or 0 based on the element ‘g’ is present in the set or
not.
 setname.lower_bound(const g) – Returns an iterator to the first element that is equivalent
to ‘g’ or definitely will not go before the element ‘g’ in the set.
 setname.upper_bound(const g) – Returns an iterator to the first element that is equivalent
to ‘g’ or definitely will go after the element ‘g’ in the set.
 setname.equal_range(k)– The function returns an iterator of pairs. (key_comp). The pair
refers to the range that includes all the elements in the container which have a key
equivalent to k.
 setname.emplace (value)– This function is used to insert a new element into the set
container, only if the element to be inserted is unique and does not already exists in the
set.
Time Complexity : O(logn)
emplace() vs insert
When we use insert, we create an object and then insert it into the multiset. With emplace(), the
object is constructed in-place.
 emplace_hint()– Returns an iterator pointing to the position where the insertion is done. If
the element passed in the parameter already exists, then it returns an iterator pointing to
the position where the existing element is.
 set1.swap (set2)– This function is used to exchange the contents of two sets but the sets
must be of same type, although sizes may differ.
 operator= – The ‘=’ is an operator in C++ STL which copies (or moves) a set to another set
and set::operator= is the corresponding operator function.
 get_allocator()– Returns the copy of the allocator object associated with the set.

Vous aimerez peut-être aussi