Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Last Class Quiz - Working with Hash Table
//clang 3.8.0 #include <stdio.h> #include <unordered_map> #include <cstdlib> #include <utility> #include <string> #include <iostream> using namespace std; int main(void) { unordered_map<string, char> myMap; //Here I show how you can insert things into the map char value; for(int i = 0; i < 26; i++){ string key = "key_" + to_string(i); value = 65 + (i % 26); myMap.insert({key, value}); } unordered_map<string, char>::const_iterator got; for(int i = 0; i < 26; i++){ string key = "key_" + to_string(i); got = myMap.find(key); //lookup elements cout << "Key: key_" << i << " Value: " << got->second << endl; } cout << endl; //Determine an item is not in the hash table for(int i = 20; i < 29; i++){ string key = "key_" + to_string(i); cout << "Testing key: " << key; if(myMap.count(key)){ cout << " Item in hash table!" << endl; } else{ cout << " Not in hash table!" << endl; } } cout << endl; //Print contents of the Hash Table for( got = myMap.begin(); got != myMap.end(); got++){ cout << "Key: " << got->first << " Value: " << got->second << endl; } }
run
|
edit
|
history
|
help
0
Mi primer ejemplo con RexTester colgado en My wall
std::reference_wrapper
Deleted special operations are propagated to derived class
Rounding float to nearest 1000
001
back_inserter example
Crow unordered_map Quiz
ghfhfgh
Math1
BucketSort