![]() |
In C++ STL (Standard Template Library), a set is a container that stores unique elements in a sorted order. In this article, we will learn how to replace a specific element in a set in C++. Example: Input: Replace Specific Element in a Set in C++In C++, we can easily replace a specific element in a set by removing the old element using the std::set::erase() function and then insert the new element using the std::set::insert() function. Syntaxset_name.erase(value_to_replace); // Erase the old element C++ Program to Replace Specific Element in a SetBelow is the Implementation of the above approach: C++
Output
Initial Set: 10 20 30 Modified Set: 10 25 30 Time Complexity: O(logN)
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |