Correct some mistakes in treap functions
This commit is contained in:
parent
734588316d
commit
e5bed9f8fe
1 changed files with 5 additions and 2 deletions
7
file.hpp
7
file.hpp
|
@ -30,16 +30,19 @@ public:
|
|||
// Hopefully with sizes
|
||||
two_lines split(line *l, count_type k) {
|
||||
if(l == nullptr) return {nullptr, nullptr};
|
||||
// TODO ??????? sizes dont add up
|
||||
|
||||
if(get_size(l->left) >= k) {
|
||||
// In the left subtree
|
||||
auto two = split(l->left, k);
|
||||
l->left = two.second;
|
||||
l->size -= get_size(two.first);
|
||||
return {two.first, l};
|
||||
}
|
||||
else {
|
||||
// In the right subtree
|
||||
auto two = split(l->right, k - (1+get_size(l->left)));
|
||||
l->right = two.first;
|
||||
l->size -= get_size(two.second);
|
||||
return {l, two.second};
|
||||
}
|
||||
|
@ -104,8 +107,8 @@ public:
|
|||
}
|
||||
// Line removal
|
||||
void remove(count_type k) {
|
||||
auto two = split(root, k);
|
||||
two.first = split(two.first, k-1).first;
|
||||
auto two = split(root, k+1);
|
||||
two.first = split(two.first, k).first;
|
||||
join(two);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue