From e207fb2b7b1bf94aec305d3a35d69ba82340a045 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:07:14 +0530 Subject: [PATCH] Create Inorder Traversal --- Inorder Traversal | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Inorder Traversal 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; + } +};