VOOZH about

URL: https://www.geeksforgeeks.org/cpp/unordered_map-empty-in-c-stl/

⇱ unordered_map empty in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

unordered_map empty in C++ STL

Last Updated : 12 Jun, 2023

unordered_map::empty() function is used to check whether container size is zero or not. If container size is zero then it return TRUE otherwise it return FALSE. 

Syntax: 

 unordered_map_name.empty()

Parameters: This function does not accept any parameter 

Return type: This function returns boolean value TRUE or FALSE. 

Examples: 

Input: ump = { {1, 2}, {3, 4}, {5, 6}, {7, 8}} ump.empty(); 
Output: False 

Input: ump = { }; ump.empty(); 
Output: True

Output:
ump1 size = 4
ump2 size = 0
False
True
True

Time complexity: O(1).

Auxiliary space: O(n). // n is the total number of elements in the unordered_map.

Comment