-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskiplist.h
More file actions
53 lines (35 loc) · 767 Bytes
/
skiplist.h
File metadata and controls
53 lines (35 loc) · 767 Bytes
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
#pragma once
#include <stdio.h>
#include <vector>
#define SKIP_LIST_MAX_LEVEL 32
struct node_t
{
int val;
int level;
node_t* next[SKIP_LIST_MAX_LEVEL];
node_t(int v, int l) :val(v), level(l) { for (auto i = 0u; i < SKIP_LIST_MAX_LEVEL; ++i) next[i] = nullptr; }
};
class skiplist
{
public:
skiplist();
~skiplist();
public:
void insert(int val);
void earse(int val);
int rank(int val);
int rank(int val, node_t*& lower, node_t* &upper);
node_t* lower_bound(int val);
node_t* upper_bound(int val);
node_t* get(int idx);
//·µ»ØÏ½ç
node_t* find(int key);
void print();
size_t level();
protected:
int random_generate_level();
private:
float rate_ = 0.5;
int max_level_;
node_t *head_;
};