Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Latest commit

 

History

History
31 lines (22 loc) · 785 Bytes

size.md

File metadata and controls

31 lines (22 loc) · 785 Bytes

size

Description : This function is used to return size of an unordered map.

Example :

// Demonstrates size() 
#include <iostream>
#include <unordered_map>

int main(){
    //declares an empty map. O(1)
    std::unordered_map<char, int> mymap; 

    //print size of mymap before inserting key and value in unordered_map
    std::cout << "mymap size is = " <<mymap.size()<< '\n';
    
    //inserting in to unordered_map with O(1) time on average
    mymap.insert({'A', 1});
    mymap.insert({'b', 2});
    mymap.insert({'c', 3});
  
    //print size of mymap After inserting key and value in unordered_map
    std::cout << "mymap size is = " <<mymap.size()<< '\n';

    return 0;
}

Run Code