-
Notifications
You must be signed in to change notification settings - Fork 0
/
skiplist_test.cpp
73 lines (64 loc) · 1.37 KB
/
skiplist_test.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include "skiplist.h"
using namespace std;
using namespace wangbb;
int main()
{
SkipList<int> skipList;
skipList.add(1);
skipList.add(4);
skipList.add(6);
skipList.add(7);
skipList.add(9);
skipList.add(11);
skipList.add(70);
cout << "initially list size = " << skipList.size() << endl;
const SkipList<int>::Node *u = skipList.header();
while (u != nullptr)
{
cout << u->val << endl;
u = u->next[0];
}
cout << endl;
int val1 = 70;
int *found1 = skipList.find(val1);
if (found1 == nullptr)
{
cout << "not found " << val1 << endl;
}
else
{
cout << "find " << val1 << " return " << *found1 <<endl;
}
int val2 = 10;
int *found2 = skipList.find(val2);
if (found2 == nullptr)
{
cout << "not found " << val2 << endl;
}
else
{
cout << "find " << val2 << " return " << *found2 <<endl;
}
int val3 = 80;
int *found3 = skipList.find(val3);
if (found3 == nullptr)
{
cout << "not found " << val3 << endl;
}
else
{
cout << "find " << val3 << " return " << *found3 <<endl;
}
skipList.remove(6);
skipList.remove(1);
cout << "after remove list size = " << skipList.size() << endl;
const SkipList<int>::Node *v = skipList.header();
while (v != nullptr)
{
cout << v->val << endl;
v = v->next[0];
}
cout << endl;
return 0;
}