-
Notifications
You must be signed in to change notification settings - Fork 0
/
skiplist.hpp
85 lines (70 loc) · 1.69 KB
/
skiplist.hpp
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
#ifndef __SKIPLIST__
#define __SKIPLIST__
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include "student.hpp"
#ifndef MaxLevel
#define MaxLevel 16
#endif
#ifndef MaxValue
#define MaxValue 100000000
#endif
class snode
{
private:
int key; /*the student id of each node*/
student *ptr; /*a pointer to the student record of each node*/
snode **next; /*an array of pointers to the next nodes according to the skiplist implementation*/
public:
snode(int st);
~snode();
inline void printall();
inline int getkey();
inline student* getstudent();
inline void setstudent(student *st);
inline snode *getnext(int i);
inline void setnext(int i, snode *s);
};
inline void snode::printall(){
ptr->printall();
}
inline int snode::getkey(){
return key;
}
inline student* snode::getstudent(){
return ptr;
}
inline void snode::setstudent(student *st){
ptr=st;
}
inline snode *snode::getnext(int i){
return next[i];
}
inline void snode::setnext(int i, snode *s){
next[i]=s;
}
class slist
{
private:
snode* header; /*pointer to the first node of the list(doesn't include record, implementation functions use)*/
snode* termnode; /*pointer to the last node of the list(doesn't include record, implementation functions use)*/
int curlvl; /*current level of the "highest" list node*/
int size; /*current amount of nodes in the list WITHOUT THE HEADER AND TERMNODE*/
public:
slist();
~slist();
int randomlvl();
student* search(int searchKey);
void insert(int searchKey,student *newValue);
int deletestud(int searchKey);
void printlist();
inline float getsize();
float raverege(int from, int to);
void bottom(int k);
void f(float gp);
};
inline float slist::getsize(){
return size;
}
#endif