Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. virtual void pop() {
  2. // we make a container, we put the start node in, and it's children's
  3. // and siblings
  4. std::deque<Node *> dq;
  5. // case for when it's only one item
  6. if (root->child == nullptr) {
  7. // delete the root, and make it null ptr
  8. delete root;
  9. root = nullptr;
  10. }
  11. // case for when it's a parent, and a child only
  12. else if (root->child->sibling == nullptr) {
  13. // now we delete the root, and make it null ptr
  14. dq.push_back(root->child);
  15. root->child->previous = nullptr;
  16. root = dq.front();
  17. dq.pop_front();
  18. }
  19. // normal case when there are multiple childrens
  20. else {
  21. root->child->previous = nullptr;
  22.  
  23. dq.push_back(root->child);
  24. // we add all the siblings
  25. while (dq.back()->sibling != nullptr) {
  26. dq.push_back(dq.back()->sibling);
  27. }
  28. // now break all the links so we can remeld
  29. for (unsigned int i = 0; i < dq.size(); ++i) {
  30. dq[i]->sibling = nullptr;
  31. dq[i]->previous = nullptr;
  32. }
  33.  
  34. // make root the front, popfront, meld the next, pop front, and continue
  35. while (dq.size() > 1) {
  36. root = dq.front();
  37. dq.pop_front();
  38. meld(dq.front());
  39. dq.pop_front();
  40. // then we push this value to the back
  41. dq.push_back(root);
  42. }
  43. }
  44.  
  45. // decrease size when we pop
  46. sizeVars--;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement