C++ || straightforward iterative (BFS and DFS) and recursive solution
TODO(heder): Insert cute cat meme to ask for up-votes. ;)\n\nUsing a pointer to a TreeNode* leads to a straight forward iterative solution. These pointers to po
**TODO(heder): Insert cute cat meme to ask for up-votes. ;)**\n\nUsing a pointer to a ```TreeNode*``` leads to a straight forward iterative solution. These pointers to pointers are later "patched" as the sub trees are being consructed.\n\n**iterative BFS version**:\n\n```\n    TreeNode* sortedArrayToBST(vector<int>& nums) {\n        typedef vector<int>::const_iterator Iter;\n        queue<tuple<TreeNode**, Iter, Iter>> q;\n\n        TreeNode* ans = nullptr;\n        q.push({&ans, cbegin(nums), cend(nums)});\n\n        while (!empty(q)) {\n            auto [nptr, b, e] = q.front(); q.pop();\n\n            if (b == e) continue;\n\n            Iter mid = next(b, distance(b, e) / 2);\n            *nptr = new TreeNode(*mid);\n\n            q.push({&(*nptr)->left, b, mid});\n            q.push({&(*nptr)->right, mid + 1, e});\n        }\n\n        return ans;\n    }\n```\n\n**iterative DFS Version**\n\nIt doesn\'t really matter in which order we create the tree, so we can use a ```stack<>``` as well.\n\n```\n    TreeNode* sortedArrayToBST(vector<int>& nums) {\n        typedef vector<int>::const_iterator Iter;\n        stack<tuple<TreeNode**, Iter, Iter>> st;\n\n        TreeNode* ans = nullptr;\n        st.push({&ans, cbegin(nums), cend(nums)});\n\n        while (!empty(st)) {\n            auto [nptr, b, e] = st.top(); st.pop();\n\n            if (b == e) continue;\n\n            Iter mid = next(b, distance(b, e) / 2);\n            *nptr = new TreeNode(*mid);\n\n            st.push({&(*nptr)->left, b, mid});\n            st.push({&(*nptr)->right, mid + 1, e});\n        }\n\n        return ans;\n    }\n```\n\n**recursive**\n\nPersonally I find the recursive version clearer and easier to understand:\n\n```\n    TreeNode* sortedArrayToBST(vector<int>& nums) {\n        return sortedArrayToBST(cbegin(nums), cend(nums));\n    }\n\n    template <typename iterator>\n    TreeNode* sortedArrayToBST(iterator b, iterator e) {\n        if (b == e) return nullptr;\n\n        iterator mid = next(b, distance(b, e) / 2);\n        return\n            new TreeNode(\n                *mid,\n                sortedArrayToBST(b, mid),\n                sortedArrayToBST(mid + 1, e));\n    }\n```\n\n_As always: Feedback, questions, and comments are welcome. Leaving an up-vote sparks joy! :)_\n\n**p.s. Join us on the [LeetCode The Hard Way Discord Server](https://discord.gg/hFUyVyWy2E)!**\n
['Recursion', 'C', 'Iterator']