Tag: an
How to Insert elements in an unordered_set in C++11
std::unordered_set provides the different overloaded versions of insert() member function to insert elements i.e. pair<iterator,bool> insert ( const value_type& val ); void insert ( InputIterator first, InputIterator last ); void insert ( initializer_list<value_type> il ); Let’s see each of them in detail Advertisements Inserting element in unordered_set by value For this we will use basic …
How to Insert elements in an unordered_set in C++11Read More
How to initialize an unordered_set in C++11
In this article we will discuss the different ways to initialize an unordered_set. Creating an empty unordered_set and then inserting elements in it is easy. But its not the practical scenario always. Many times we need to initialize an unordered_set while creation. For that it provides different overloaded constructors and we will use some of …
How to Search an element in unordered_set
In this article we will see how to search if an element is present in an unordered_set or not. std::unordered_set provides a member function find () that accepts an element of same type as set and search for that element in set. Advertisements If element is found then it returns the iterator pointing to that …
How to iterate over an unordered_map in C++11
In this article we will discuss the different ways to iterate over an unordered_map. First lets create an unordered_map and then we will see the different ways to iterate over it. // Initialize an unordered_map through initializer_list std::unordered_map<std::string, int> wordMap({{ “First”, 1 },{ “Second”, 2 },{ “Third”, 3 }}); Iterating an unordered_map using range based …
Different Ways to initialize an unordered_map
In this article we will discuss the different ways to initialize an unordered_map. unordered_map provides different overloaded constructors. We will use some of them to initialize an unordered_set in 3 different ways i.e. Initializing through an initializer_list Initializing through a iterable range. Initializing through an another map. Lets see them in detail, Advertisements Initializing an unordered_map …
Different ways to insert elements in an unordered_map
In this article we will discuss the different ways to insert elements in an unordered_map. Unordered_map provides different overloaded versions of insert() member function to insert key value pairs in an unordered_map. Lets discuss them one by one. Advertisements Inserting multiple elements in unordered_map through an initializer_list unordered_map provides an overloaded version of insert that …
Different ways to insert elements in an unordered_mapRead More
How to find an element in unordered_map
In this article we will discuss how to find an element in an unordered_map. An unordered_map store elements in key – value pair. Hence to search an element we need to search if the key exists in an unordered_map or not. For this unordered_map provides a member function find() i.e. Advertisements iterator find ( const …
How to Erase / Remove an element from an unordered_map
In this article we will discuss the different ways to remove an element from an unordered_map. Unordered_map provides different overloaded version of erase() member function to delete key value pairs from map. Advertisements Erasing an element from an unordered_map by key Unordered_map provides following overloaded version of erase() that accepts a key by value and …
How to Erase / Remove an element from an unordered_mapRead More
How to pass an ArrayList to varargs method
In this article we will see how to pass an arraylist to a method expecting vararg as an method argument. Suppose we have a method that accepts varargs of type Integer and calculates the sum of them i.e. Advertisements int calculateSum(Integer… nums) { int sum = 0; for(int num : nums) { sum = sum + …
C++ List – Find | Contains : How to search an element in std::list ?
In this article we will discuss different ways to find or search a given element in the list. std::list does not provide ant find() or contains() method. So, if we want to search for an element in list or check if an element exists in std::list, then we not to write some code for it i.e. …
C++ List – Find | Contains : How to search an element in std::list ?Read More