diff --git a/Inorder Traversal b/Inorder Traversal new file mode 100644 index 0000000..1c7be6a --- /dev/null +++ b/Inorder Traversal @@ -0,0 +1,23 @@ +class Solution { + private: + void inorderTraversal(Node* root, vector &ans){ + if(root==nullptr){ + return; + } + + inorderTraversal(root->left, ans); + ans.push_back(root->data); + inorderTraversal(root->right, ans); + + } + public: + // Function to return a list containing the inorder traversal of the tree. + vector inOrder(Node* root) { + if(root==nullptr){ + return {}; + } + vectorans; + inorderTraversal(root, ans); + return ans; + } +};