![]() |
In C++ STL (Standard Template Library), the set container represents a collection of unique, sorted elements. In this article, we will see how to an element in a set in C++ using iterators. Example Input: mySet = {1, 8, 99, 444, 521 } Output: mySet Value at Index 2: 99 Access an Element in a Set in C++We can use the set iterators provided by the function std::set::begin() to access the elements of a set. Iterators are like pointers, we can access any index value using this iterator by incrementing and decrementing.
C++ Program to Access an Element in a Set using IteratorsBelow is the Implementation of the above approach: C++
Output
Third element in the set (Using Iterators): 30 Time Complexity: O(logN) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |