From 645c17b274abed8ff2378f6bfbe108f0a3f3ab2d Mon Sep 17 00:00:00 2001 From: Manali21Gupta Date: Mon, 9 Mar 2020 14:40:41 +0530 Subject: [PATCH] unordered_map clear function --- unordered_map/clear.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 unordered_map/clear.md diff --git a/unordered_map/clear.md b/unordered_map/clear.md new file mode 100644 index 00000000..08acfd05 --- /dev/null +++ b/unordered_map/clear.md @@ -0,0 +1,34 @@ +# clear + +**Description :** This function is used to remove all elements from the container. + +**Example** : + +```cpp +// Demonstrates clear() +#include +#include + +int main(){ + //declares an empty map. O(1) + std::unordered_map my_map; + + // inserting in to unordered_map with O(1) time on average + my_map.insert({'A', 1}); + my_map.insert({'B', 2}); + my_map.insert({'C', 3}); + + //Print the size of the container + std::cout << "Size of unordered_map before calling clear function: " << my_map.size() << std::endl; + + //Deleting all elements by calling clear function + my_map.clear(); + + //Print the size of the container + std::cout << "Size of unordered_map after calling clear function: " << my_map.size() << std::endl; + + return 0; +} + +``` +**[Run Code](https://rextester.com/BQLV19570)** \ No newline at end of file