Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Version from Polina, hope it works..
- template <class Value, class Key, int numLevels>
- void SkipList<Value, Key, numLevels>::removeNext(SkipList::Node* node)
- {
- using namespace std;
- if (node == nullptr || node->next == nullptr || node->next == Base::_preHead)
- throw std::invalid_argument("You can't remove next node!");
- Node* toDelete = node->next;
- Node* currNode = Base::_preHead;
- int level = currNode->levelHighest;
- while (level >= 0)
- {
- Node* right = currNode->nextJump[level];
- //равенство ключей - но ссылки могут быть не равны!
- //случай, когда ключи повторяются
- if (right->key == toDelete->key)
- {
- //отец предполагаемого удаляемого (равного по ссылке)
- Node* amongEqual = currNode;
- while (amongEqual->nextJump[level] != Base::_preHead && amongEqual->nextJump[level]->key == toDelete->key)
- {
- if (amongEqual->nextJump[level] == toDelete)
- {
- cout << "delete in equal" << endl;
- //переставляем ссылку
- amongEqual->nextJump[level] = amongEqual->nextJump[level]->nextJump[level];
- //едем вправо
- currNode = amongEqual;
- break;
- }
- cout << "in equal: right" << endl;
- amongEqual = amongEqual->nextJump[level];
- }
- cout << "down =" << endl;
- level--;
- }
- else if (right == Base::_preHead || right->key > toDelete->key)
- {
- cout << "down >" << endl;
- //едем вниз
- level--;
- }
- else
- {
- cout << "right" << endl;
- //едем вправо
- currNode = right;
- }
- }
- node->next = node->next->next;
- delete toDelete;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement