Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Saam hash example
#include <iostream> #include <string> #include <vector> #include <queue> #include <unordered_map> using namespace std; class HashTable { private: unordered_map<int, string> DB; public: void insert(int key, string item); string getItem(int key); bool inHash(int key); void printTable(); }; void HashTable::insert(int key, string item) { auto hashTablePointer = DB.find(key); if(hashTablePointer != DB.end()) { cout << "Already in table" << endl; return; } DB[key] = item; } string HashTable::getItem(int key) { if(inHash(key)) { return DB[key]; } return "not in table"; } bool HashTable::inHash(int key) { return (DB.find(key) != DB.end()); } void HashTable::printTable() { for(auto local_it = DB.begin(); local_it != DB.end(); ++local_it) { cout << local_it->second << endl; } } int main() { HashTable myTable; cout << "inserting elements" << endl; myTable.insert(1, "one"); myTable.insert(2, "two"); myTable.insert(3, "three"); myTable.insert(4, "four"); cout << "inserted 4 elements" << endl; cout << "getting element 1" << endl; cout << myTable.getItem(1) << endl; cout << "printing table" << endl; myTable.printTable(); }
run
|
edit
|
history
|
help
0
First test
Exploring stringstreams
DESim Example with Hash Table Starter Code
set/map equal_range bug in libc++
Balanced Insert Example
(non?)-template template parameters for container stream insertion
bank queue
Tilted uniform distribution random number generator over min/max range
std::function copies
10 naturalnumbers