Skip to content

Instantly share code, notes, and snippets.

@epsilon-phase
Created November 19, 2018 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epsilon-phase/68e1174c5921f2cb0f52b6fc572d9341 to your computer and use it in GitHub Desktop.
Save epsilon-phase/68e1174c5921f2cb0f52b6fc572d9341 to your computer and use it in GitHub Desktop.
c++ question thingy
BST& BST::operator=(BST&& otherBST) {
if (this != &otherBST) {
if (root) {
stack <Node**> nodeStack;
nodeStack.push(&root);
Node **currentNode = nullptr;
while (!nodeStack.empty()) {
currentNode = nodeStack.top();
nodeStack.pop();
if ((*currentNode)->rlink) {
nodeStack.push(&(*currentNode)->rlink);
}
if ((*currentNode)->llink) {
nodeStack.push(&(*currentNode)->llink);
}
delete *currentNode;
*currentNode = nullptr;
}
cout << root << endl; // This is where it seems like root is not being deleted correctly/nullptr'd.
}
root = move(otherBST.root);
otherBST.root = nullptr;
}
else {
cerr << "ERROR: Cannot assign to self." << endl;
}
return *this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment