hashmap in c++
C++
#include <iostream>
#include <iterator>
#include <map>
using namespace std;
int main()
{
// empty map container
map<int, int> gquiz1;
// insert elements in random order
gquiz1.insert(pair<int, int>(1, 40));
gquiz1.insert(pair<int, int>(2, 30));
gquiz1.insert(pair<int, int>(3, 60));
gquiz1.insert(pair<int, int>(4, 20));
gquiz1.insert(pair<int, int>(5, 50));
gquiz1.insert(pair<int, int>(6, 50));
gquiz1.insert(pair<int, int>(7, 10));
// printing map gquiz1
map<int, int>::iterator itr;
cout << "\nThe map gquiz1 is : \n";
cout << "\tKEY\tELEMENT\n";
for (itr = gquiz1.begin(); itr != gquiz1.end(); ++itr) {
cout << '\t' << itr->first
<< '\t' << itr->second << '\n';
}
cout << endl;
// assigning the elements from gquiz1 to gquiz2
map<int, int> gquiz2(gquiz1.begin(), gquiz1.end());
// print all elements of the map gquiz2
cout << "\nThe map gquiz2 after"
<< " assign from gquiz1 is : \n";
cout << "\tKEY\tELEMENT\n";
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
cout << '\t' << itr->first
<< '\t' << itr->second << '\n';
}
cout << endl;
// remove all elements up to
// element with key=3 in gquiz2
cout << "\ngquiz2 after removal of"
" elements less than key=3 : \n";
cout << "\tKEY\tELEMENT\n";
gquiz2.erase(gquiz2.begin(), gquiz2.find(3));
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
cout << '\t' << itr->first
<< '\t' << itr->second << '\n';
}
// remove all elements with key = 4
int num;
num = gquiz2.erase(4);
cout << "\ngquiz2.erase(4) : ";
cout << num << " removed \n";
cout << "\tKEY\tELEMENT\n";
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
cout << '\t' << itr->first
<< '\t' << itr->second << '\n';
}
cout << endl;
// lower bound and upper bound for map gquiz1 key = 5
cout << "gquiz1.lower_bound(5) : "
<< "\tKEY = ";
cout << gquiz1.lower_bound(5)->first << '\t';
cout << "\tELEMENT = "
<< gquiz1.lower_bound(5)->second << endl;
cout << "gquiz1.upper_bound(5) : "
<< "\tKEY = ";
cout << gquiz1.upper_bound(5)->first << '\t';
cout << "\tELEMENT = "
<< gquiz1.upper_bound(5)->second << endl;
return 0;
}
Also in C++:
- Title
- primos menores que
- Category
- C++
- Title
- bellman ford algorithm cp algorithm
- Category
- C++
- Title
- container class in c++
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- how to compare two strings lexicographically in c++
- Category
- C++
- Title
- c++ main function
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- string to number in c++
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- leveling system c++
- Category
- C++
- Title
- remove from unordered_set c++
- Category
- C++
- Title
- c++ empty stream
- Category
- C++
- Title
- std::reverse
- Category
- C++
- Title
- heap in cpp stl
- Category
- C++
- Title
- ue4 c++ enum
- Category
- C++
- Title
- delete a double pointer c++
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- pointer related problems dangling/wild pointers c++
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- c++ replace n substrings
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- screen record ios simulator
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- arrow operator c++
- Category
- C++
- Title
- c++ sort vector of objects by property
- Category
- C++
- Title
- Read multiple files(.txt) c++
- Category
- C++
- Title
- c++ clear stream
- Category
- C++
- Title
- c++ raw string
- Category
- C++
- Title
- c++ initialization list
- Category
- C++
- Title
- calling by reference and pointers c++
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- c++ lettura file
- Category
- C++
- Title
- c++ looping through a vector
- Category
- C++
- Title
- minmax_element c++
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- c++ replace substrings
- Category
- C++
- Title
- c++ pointers
- Category
- C++
- Title
- how to sort a vector in c++
- Category
- C++
- Title
- how to measure program run time in c++
- Category
- C++
- Title
- c++ remove space from string
- Category
- C++
- Title
- c++ get type name of object
- Category
- C++
- Title
- check if intent has extras
- Category
- C++
- Title
- matrix transpose tiling
- Category
- C++
- Title
- how initilaize deffult value to c++ class
- Category
- C++
- Title
- c++ string to vector int
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- c++ clamp
- Category
- C++
- Title
- c++ wait for user input
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- c++ dereference a pointer
- Category
- C++
- Title
- insert at position in vector c++
- Category
- C++
- Title
- coping 2d vector in cpp
- Category
- C++
- Title
- hashset in c++
- Category
- C++
- Title
- how to modulo 10^9+7
- Category
- C++
- Title
- c++ random
- Category
- C++
- Title
- passing a vector to a function c++
- Category
- C++
- Title
- c++ program to input and print text using Dynamic Memory Allocation.loop
- Category
- C++
- Title
- lisy stl C++
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- c++ while loop code
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- print type cpp
- Category
- C++
- Title
- jump to case label c++
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- what is time complexity of min_element()
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- ue4 c++ overlapping functions cpp setup
- Category
- C++
- Title
- calling a method on an object c++
- Category
- C++
- Title
- error: redefinition of ‘class Customer’
- Category
- C++
- Title
- dijkstra in c++
- Category
- C++
- Title
- creare array con c++
- Category
- C++
- Title
- unordered_set c++
- Category
- C++
- Title
- calling by reference c++
- Category
- C++
- Title
- stringstream in c++ with delimiter
- Category
- C++
- Title
- c++ give options
- Category
- C++
- Title
- c++ formatting
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- Check if a Number is Odd or Even using Bitwise Operators
- Category
- C++
- Title
- graph using djacency matrix c++
- Category
- C++
- Title
- c++ ros publisher
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++
- Title
- convert int to string c++
- Category
- C++
- Title
- compare function in sort c++ stl
- Category
- C++
- Title
- c++ reverse vector
- Category
- C++
- Title
- runtime array size c++
- Category
- C++
- Title
- how to calculate inverse trigonometric values in c++
- Category
- C++
- Title
- how to inject a dll into a game c++
- Category
- C++
- Title
- coronavirus
- Category
- C++
- Title
- runtime error in c++
- Category
- C++
- Title
- how to iterate through a map in c++
- Category
- C++
- Title
- sort function in c++
- Category
- C++
- Title
- c++ random numbers
- Category
- C++
- Title
- c++ unittest in ros
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- c++ public inheritance not getting protected
- Category
- C++
- Title
- removing repeated characters in a string c++
- Category
- C++
- Title
- c++ declare variable
- Category
- C++
- Title
- restting a queue stl
- Category
- C++