![]() |
In C++, a set is a container provided by the Standard Template Library(STL) that stores unique elements of the same type in a sorted order. In this article, we will learn how to use an iterator to insert elements into a set in C++. Example: Input: myVector = {10, 20, 30, 40, 50} Output: myVector = {10, 20, 30, 40, 50, 60, 70, 80} Insert Elements into a Set Using Iterator in C++In C++, the std::set contains the std::set::insert() member function that also accepts iterators denoting a range of elements to be inserted in the set. These iterators can belong to any data container such as vector, deque, and even another set. C++ Program to Insert Elements into a Set Using IteratorC++
Output
Before Insertion:10 20 30 40 50 After Insertion:10 20 30 40 50 60 70 80 Time Complexity: O(M logN) where N is the number of elements in the set and M is the number of elements in the vector.
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |