From 94791ce3fce073cff087028c3d76f9a768d78df2 Mon Sep 17 00:00:00 2001 From: Manmeet Singh <73221442+ManmeetSingh27@users.noreply.github.com> Date: Fri, 22 Oct 2021 21:49:12 +0530 Subject: [PATCH] Inorder Traversal --- Data Structure/Trees/InorderTraversal.cpp | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Data Structure/Trees/InorderTraversal.cpp diff --git a/Data Structure/Trees/InorderTraversal.cpp b/Data Structure/Trees/InorderTraversal.cpp new file mode 100644 index 00000000..e993e794 --- /dev/null +++ b/Data Structure/Trees/InorderTraversal.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; + +struct Node { + int data; + struct Node *left, *right; + Node(int data) + { + this->data = data; + left = right = NULL; + } +}; + +void printInorder(struct Node* node) +{ + if (node == NULL) + return; + + printInorder(node->left); + + cout << node->data << " "; + + printInorder(node->right); +} + +int main() +{ + struct Node* root = new Node(1); + root->left = new Node(2); + root->right = new Node(3); + root->left->left = new Node(4); + root->left->right = new Node(5); + + cout << "Inorder traversal of binary tree is \n"; + printInorder(root); + + return 0; +}