Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
HashMap
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Title of this code #include <iostream> #include <list> using namespace std; template<class T1, class T2> class MyMap { public: struct Node { long key_hash; T2 value; }; private: hash<T1> hashing; list<Node*> nodes; public: MyMap(){}; ~MyMap(){}; T2& operator[](const T1&); }; template<class T1, class T2> T2& MyMap<T1, T2>::operator[](const T1& key) { long key_hash = hashing(key); //typename list<Node*>::iterator it; if (!nodes.empty()) for (auto it = nodes.begin(); it != nodes.end(); ++it) { if ((*it)->key_hash == key_hash) return (*it)->value; } Node *node = new Node(); node->key_hash = key_hash; node->value = 0; nodes.push_back(node); return node->value; } int main() { MyMap<string,int> m; string s = "hello"; m[s] = 10; cout << m[s]; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.56 sec, absolute running time: 0.16 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0.73 sec (cached)
fork mode
|
history
|
discussion
10