Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- virtual void pop() {
- // we make a container, we put the start node in, and it's children's
- // and siblings
- std::deque<Node *> dq;
- // case for when it's only one item
- if (root->child == nullptr) {
- // delete the root, and make it null ptr
- delete root;
- root = nullptr;
- }
- // case for when it's a parent, and a child only
- else if (root->child->sibling == nullptr) {
- // now we delete the root, and make it null ptr
- dq.push_back(root->child);
- root->child->previous = nullptr;
- root = dq.front();
- dq.pop_front();
- }
- // normal case when there are multiple childrens
- else {
- root->child->previous = nullptr;
- dq.push_back(root->child);
- // we add all the siblings
- while (dq.back()->sibling != nullptr) {
- dq.push_back(dq.back()->sibling);
- }
- // now break all the links so we can remeld
- for (unsigned int i = 0; i < dq.size(); ++i) {
- dq[i]->sibling = nullptr;
- dq[i]->previous = nullptr;
- }
- // make root the front, popfront, meld the next, pop front, and continue
- while (dq.size() > 1) {
- root = dq.front();
- dq.pop_front();
- meld(dq.front());
- dq.pop_front();
- // then we push this value to the back
- dq.push_back(root);
- }
- }
- // decrease size when we pop
- sizeVars--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement