Created
November 19, 2018 04:51
-
-
Save epsilon-phase/68e1174c5921f2cb0f52b6fc572d9341 to your computer and use it in GitHub Desktop.
c++ question thingy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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