-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkipList.h
57 lines (46 loc) · 902 Bytes
/
SkipList.h
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
#ifndef __SKIPLIST_H__
#define __SKIPLIST_H__
#define MAX_LEVEL 32
template <class T>
class SkipNode {
public:
//T value;
//SkipNode<T> **forward; //array of poniter
SkipNode(int level, const T &value) {
forward = new SkipNode<T> * [level + 1];
memset(forward, 0, sizeof(SkipNode<T>*) * (level + 1));
this->value = value;
}
~SkipNode() {
delete[] forward;
}
public:
T value;
SkipNode<T> **forward;
};
template <class T>
class SkipSet {
public:
//SkipNode<T> *header;
//int level;
SkipSet() {
header = new SkipNode<T>(MAX_LEVEL, T());
level = 0;
}
~SkipSet() {
delete header;
}
void print() const;
bool contains(const T &) const;
void insert(const T &);
void erase(const T &);
T advance(const T &);
T current();
T next();
private:
SkipNode<T> *header;
int level;
public:
SkipNode<T> *cur;
};
#endif // __SKIPLIST_H__