-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathHT2.cpp
54 lines (51 loc) · 1.18 KB
/
HT2.cpp
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
#include <array>
#include <list>
#include <vector>
#include <iostream>
using namespace std;
typedef unsigned long ul;
class Entity {
ul key;
ul value;
friend class HT;
public: Entity(ul k=0, ul v=0) :key(k), value(v) {}
};
class HT {
array<list<Entity>, 5> container;
public:
ul getIndex(ul key) { return key % 5; }
void add(ul key, ul value) { container[getIndex(key)].push_back(Entity(key,value)); }
void display() {
for (size_t i = 0;i < container.size();++i) {//recorre el array
cout << i << "->";
/*for (list<Entity>::iterator it = container[i].begin();it != container[i].end();++it) {
cout <<"("<<(*it).key << "-" << (*it).value << ")-> ";
}*/
for (auto it:container[i]) {
cout << "(" << it.key << "-" << it.value << ")-> ";
}
cout << "\n";
}
}
};
int main() {
/*vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
vec.push_back(4);
vec.push_back(5);
//vector<int>::iterator i;//recorrer direcciones de memoria
for (vector<int>::iterator i = vec.begin();i != vec.end();++i) {
cout << *i << " ";
}
*/
HT ht;
ht.add(500,100);
ht.add(1000,150);
ht.add(738,200);
ht.add(801,250);
ht.add(603,300);
ht.display();
return 0;
}