C++ Simple and Clean Recursive and Iterative Solutions
Recursive:\n\nclass Solution {\npublic:\n    void inorder(TreeNode* root, int& k) {\n        if (!root) return;\n        inorder(root->left, k);\n        if (--
**Recursive:**\n```\nclass Solution {\npublic:\n    void inorder(TreeNode* root, int& k) {\n        if (!root) return;\n        inorder(root->left, k);\n        if (--k == 0) res = root->val;\n        inorder(root->right, k);\n    }\n    \n    int kthSmallest(TreeNode* root, int k) {\n        inorder(root, k);\n        return res;\n    }\n    \nprivate:\n    int res;\n};\n```\n****\n**Iterative:**\n```\nclass Solution {\npublic:\n    int kthSmallest(TreeNode* root, int k) {\n        stack<TreeNode*> s;\n        while (root || !s.empty()) {\n            while (root) {\n                s.push(root);\n                root = root->left;\n            }\n            \n            root = s.top();\n            s.pop();\n            \n            if (--k == 0) return root->val;\n            root = root->right;\n        }\n        return -1;\n    }\n};\n```\n**Like it? please upvote!**
['Recursion', 'C', 'Iterator']