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
Assignment Operator Example
program_4
hw1 Os
Alloc
Throttle Example (Send two requests every two seconds)
Code Rush Game Group 1
Set sub sequences.
Graphs Iteration2 Directed Graphs
001
Virtual Function Example