Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> DeepDarkFantasy(Node* init = nullptr) {
- vector<int> a;
- if (init == nullptr) init = this->root;
- stack<Node*> s;
- s.push(init);
- while (!s.empty()) {
- Node* that = s.top();
- if (that->left != nullptr) {
- s.push(that->left);
- continue;
- }
- else if (that->right != nullptr) {
- s.pop();
- if (s.size() > 0) {
- Node* temp = s.top();
- temp->left = nullptr;
- }
- s.push(that->right);
- a.push_back(that->data);
- }
- else {
- s.pop();
- if (s.size() > 0) {
- Node* temp = s.top();
- temp->left = nullptr;
- }
- a.push_back(that->data);
- }
- }
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement