DAILY LEETCODE SOLUTION || EASY C++ SOLUTION
\n//PreorderTraversal Using Recurrsion\nclass Solution {\npublic:\n    vector<int> ans;\n    void preorder(TreeNode* root)\n    {\n        if(root==NULL)\n     
```\n//PreorderTraversal Using Recurrsion\nclass Solution {\npublic:\n    vector<int> ans;\n    void preorder(TreeNode* root)\n    {\n        if(root==NULL)\n        {\n            return ;\n        }\n        ans.push_back(root->val);\n        preorder(root->left);\n        preorder(root->right);\n    }\n    vector<int> preorderTraversal(TreeNode* root) {\n        preorder(root);\n        return ans;\n    }\n};\n```\n```\n//Preorder Traversal Using Morris Traversal\nclass Solution {\npublic:\n    vector<int> preorderTraversal(TreeNode* root) {\n        vector<int> ans;\n        TreeNode* curr=root;\n        while(curr){\n            if(!curr->left){\n                ans.push_back(curr->val);\n                curr=curr->right;\n            }\n            else{\n                TreeNode* pre=curr->left;\n                while(pre->right&&pre->right!=curr){\n                    pre=pre->right;\n                }\n                if(pre->right==NULL){\n                    pre->right=curr;\n                    ans.push_back(curr->val);\n                    curr=curr->left;\n                }\n                else{\n                    pre->right=NULL;\n                    curr=curr->right;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Recursion', 'Binary Tree']