![]() |
In C++, the unordered_map is like a dictionary that stores data in the form of key-value pairs. In this article, we will learn how to delete a key-value pair from an unordered_map in C++. Example Input: Remove Key-Value Pair from Unordered Map in C++In unordered_map, we can delete a pair by using the std::unordered_map::erase() method. First, we check if a key for a pair that you want to delete exists or not. If it exists, then we remove it by simply passing that key to the erase() function. C++ Program to Delete a Pair from Unordered MapC++
Output
Unordered Map after deletion: 2: Orange 1: Apple Time Complexity: O(N) is worst case time complexity, while the average complexity is O(1).
|
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |