@@ -43,7 +43,7 @@ class Skiplist {
43
43
}
44
44
}
45
45
46
- bool search (int target) {
46
+ bool search (int target) const {
47
47
return find (target, find_prev_nodes (target)) != nullptr ;
48
48
}
49
49
@@ -82,7 +82,7 @@ class Skiplist {
82
82
}
83
83
84
84
private:
85
- SkipNode *find (int num, const vector<SkipNode *>& prevs) {
85
+ SkipNode *find (int num, const vector<SkipNode *>& prevs) const {
86
86
if (!prevs.empty ()) {
87
87
auto candidate = prevs[0 ]->nexts [0 ];
88
88
if (candidate && candidate->num == num) {
@@ -92,7 +92,7 @@ class Skiplist {
92
92
return nullptr ;
93
93
}
94
94
95
- vector<SkipNode *> find_prev_nodes (int num) {
95
+ vector<SkipNode *> find_prev_nodes (int num) const {
96
96
vector<SkipNode *> prevs (head_->nexts .size ());
97
97
auto curr = head_;
98
98
for (int i = head_->nexts .size () - 1 ; i >= 0 ; --i) {
@@ -116,7 +116,7 @@ class Skiplist {
116
116
return level;
117
117
}
118
118
119
- void print_list () {
119
+ void print_list () const {
120
120
for (int i = head_->nexts .size () - 1 ; i >= 0 ; --i) {
121
121
auto curr = head_->nexts [i];
122
122
cout << curr->num ;
@@ -163,7 +163,7 @@ class Skiplist2 {
163
163
164
164
}
165
165
166
- bool search (int target) {
166
+ bool search (int target) const {
167
167
return find (target, find_prev_nodes (target)) != nullptr ;
168
168
}
169
169
@@ -201,7 +201,7 @@ class Skiplist2 {
201
201
}
202
202
203
203
private:
204
- shared_ptr<SkipNode> find (int num, const vector<shared_ptr<SkipNode>>& prevs) {
204
+ shared_ptr<SkipNode> find (int num, const vector<shared_ptr<SkipNode>>& prevs) const {
205
205
if (!prevs.empty ()) {
206
206
auto candidate = prevs[0 ]->nexts [0 ];
207
207
if (candidate && candidate->num == num) {
@@ -211,7 +211,7 @@ class Skiplist2 {
211
211
return nullptr ;
212
212
}
213
213
214
- vector<shared_ptr<SkipNode>> find_prev_nodes (int num) {
214
+ vector<shared_ptr<SkipNode>> find_prev_nodes (int num) const {
215
215
vector<shared_ptr<SkipNode>> prevs (head_->nexts .size ());
216
216
auto curr = head_;
217
217
for (int i = head_->nexts .size () - 1 ; i >= 0 ; --i) {
@@ -235,7 +235,7 @@ class Skiplist2 {
235
235
return level;
236
236
}
237
237
238
- void print_list () {
238
+ void print_list () const {
239
239
for (int i = head_->nexts .size () - 1 ; i >= 0 ; --i) {
240
240
auto curr = head_->nexts [i];
241
241
cout << curr->num ;
0 commit comments