-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasswork.cpp
More file actions
90 lines (69 loc) · 1.51 KB
/
classwork.cpp
File metadata and controls
90 lines (69 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Hace tiempo implementamos un TRIE en C.
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <memory>
#include <unordered_map>
#include <cstring>
// Implementarlo a manera de mapa en C++:
using namespace std;
struct IterateTrie{
IterateTrie()
{}
};
using iterator = IterateTrie;
template <typename T>
class trie
{
map<T, trie> tries;
public:
void insert(const string& key, const T& value)
{
}
size_t size() const
{
}
T& operator[](const string& key) //if does not find it, creates it.
{
return (*find(key)).sencond;
}
iterator find(const string& key)
{
size_t ad = key;
}
iterator begin()
{
}
iterator end()
{
}
template <typename PROC>
void iterate_by_prefix(const string& prefix, PROC p)
{
}
};
// La idea es que dada una clave (siempre como string, dada la naturaleza del Trie),
// se pueda almacenar un valor de cualquier tipo T en el nodo específico.
int main()
{
trie<int> s;
s.insert("diez", 10);
s.insert("dieciocho", 18);
s.insert("diecinueve", 19);
s["veinte"] = 20;
s["veintiuno"] = 21;
auto it = s.find("veinte");
if (it == s.end())
cerr << "Not found\n";
else
cout << it->second << "\n";
//should iterate diez, dieciocho and diecinueve
s.iterate_by_prefix("die", [](auto& p)
{
cout << "Key: " << p.first << "; Value: " << p.second << "\n";
});
cout << "****\n";
// should get all items as pairs
for (auto& i : s) { cout << i.second << "\n"; }
}