![]() |
In C++, a set is an ordered container that stores its unique values in some given order. In this article, we will see how to find the first occurrence of a specific element in a set in C++ STL. For Example, Input: mySet = {1, 2, 3, 8, 9, 11} Target = 9 Output: Element found at Index: 4 Find the First Occurrence of an Element in a Set in C++To find the first occurrence of a given element in a set, we can use the std::set::find() member function which returns the iterator to the first occurrence of the given element in the set. If the element is not found, it returns the iterator to the end.
C++ Program to Find the First Occurrence of a Given ElementC++
Output
Element 4 found at position 3 Time complexity: O(log n) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |