`{"id":"6ec0df2a-18fd-4960-a7a7-1390365e2822","name":"In Order Morris Traversal In Binarytree","description":"<p>1. Given a Binary Tree, return inorder Traversal of it. 2. For more Information watch given video link below.</p>","inputFormat":"<p>Input is managed for you.</p>","outputFormat":"<p>Output is managed for you.</p>","constraints":"<p>0 &lt;= Number of Nodes &lt;= 10^5 -1000 &lt;= value of Node data &lt;= 1000</p>","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\n#include <queue>\r\nusing namespace std;\r\n\r\nclass TreeNode\r\n{\r\npublic:\r\n int val = 0;\r\n TreeNode* left = nullptr;\r\n TreeNode* right = nullptr;\r\n\r\n TreeNode(int val)\r\n {\r\n this->val = val;\r\n }\r\n};\r\n\r\nvector<int> morrisInTraversal(TreeNode* root) {\r\n\r\n}\r\n\r\n// input_section=================================================\r\n\r\nTreeNode* createTree(vector<int>& arr, vector<int>& IDX)\r\n{\r\n\r\n if (IDX > arr.size() || arr[IDX] == -1)\r\n {\r\n IDX++;\r\n return nullptr;\r\n }\r\n\r\n TreeNode* node = new TreeNode(arr[IDX++]);\r\n node->left = createTree(arr, IDX);\r\n node->right = createTree(arr, IDX);\r\n\r\n return node;\r\n}\r\n\r\nvoid solve()\r\n{\r\n int n;\r\n cin >> n;\r\n vector<int> arr(n, 0);\r\n for (int i = 0; i < n; i++)\r\n {\r\n cin >> arr[i];\r\n }\r\n\r\n vector<int> IDX(1, 0);\r\n TreeNode* root = createTree(arr, IDX);\r\n\r\n vector<int> ans = morrisInTraversal(root);\r\n\r\n for (int i : ans)\r\n {\r\n cout << i << \" \";\r\n }\r\n}\r\n\r\nint main()\r\n{\r\n solve();\r\n return 0;\r\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n public static Scanner scn = new Scanner(System.in);\r\n\r\n public static class TreeNode {\r\n int val = 0;\r\n TreeNode left = null;\r\n TreeNode right = null;\r\n\r\n TreeNode(int val) {\r\n this.val = val;\r\n }\r\n }\r\n\r\n public static ArrayList<Integer> morrisInTraversal(TreeNode Treenode) {\r\n return null;\r\n }\r\n\r\n // input_section=================================================\r\n\r\n public static TreeNode createTree(int[] arr, int[] IDX) {\r\n if (IDX > arr.length || arr[IDX] == -1) {\r\n IDX++;\r\n return null;\r\n }\r\n TreeNode Treenode = new TreeNode(arr[IDX++]);\r\n Treenode.left = createTree(arr, IDX);\r\n Treenode.right = createTree(arr, IDX);\r\n\r\n return Treenode;\r\n }\r\n\r\n public static void solve() {\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++)\r\n arr[i] = scn.nextInt();\r\n\r\n int[] IDX = new int;\r\n TreeNode root = createTree(arr, IDX);\r\n\r\n ArrayList<Integer> ans = morrisInTraversal(root);\r\n for (Integer i : ans)\r\n System.out.print(i + \" \");\r\n\r\n }\r\n\r\n public static void main(String[] args) {\r\n solve();\r\n }\r\n}"},"python":{"code":"def main():\r\n # Code here"}},"points":10,"difficulty":"easy","sampleInput":"15\r\n4\r\n2\r\n1\r\n-1\r\n-1\r\n3\r\n-1\r\n-1\r\n6\r\n5\r\n-1\r\n-1\r\n7\r\n-1\r\n-1","sampleOutput":"1 2 3 4 5 6 7","questionVideo":"","hints":[],"associated":[{"id":"321a84d2-27d4-4778-b77d-5ab9968a903e","name":"inorder morris traversal in binary tree MCQ 03","slug":"inorder-morris-traversal-in-binary-tree-mcq-03","type":4},{"id":"52c2950f-57af-4924-86bc-e987d1370730","name":"inorder morris traversal in binary tree MCQ 01","slug":"inorder-morris-traversal-in-binary-tree-mcq-01","type":4},{"id":"70f061ed-74af-45c7-b933-99b7bc2c42b9","name":"inorder morris traversal in binary tree MCQ 02","slug":"inorder-morris-traversal-in-binary-tree-mcq-02","type":4},{"id":"8bb3b577-cd46-4700-81a7-761056f5dd6f","name":"Inorder Morris Traversal In Binary Tree","slug":"inorder-morris-traversal-in-binary-tree","type":3},{"id":"baf59701-44bc-4a6f-b172-73bd86946781","name":"inorder morris traversal in binary tree MCQ 04","slug":"inorder-morris-traversal-in-binary-tree-mcq-04","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"2e9df04c-be14-441c-9a18-8b5a8ca6596d","name":"Trees For Intermediate","slug":"trees-for-intermediate-9994","type":0},{"id":"5d920258-7952-4c8e-abd0-2bc78609cc79","name":"In Order Morris Traversal In Binarytree","slug":"in-order-morris-traversal-in-binarytree","type":1}],"next":{"id":"f2dad269-9cd1-44d1-8539-304277b7a806","name":"In Order Morris Traversal In Binarytree","type":0,"slug":"in-order-morris-traversal-in-binarytree-zqslw"},"prev":null}}`

# In Order Morris Traversal In Binarytree

<p>1. Given a Binary Tree, return inorder Traversal of it. 2. For more Information watch given video link below.</p>

`{"id":"6ec0df2a-18fd-4960-a7a7-1390365e2822","name":"In Order Morris Traversal In Binarytree","description":"<p>1. Given a Binary Tree, return inorder Traversal of it. 2. For more Information watch given video link below.</p>","inputFormat":"<p>Input is managed for you.</p>","outputFormat":"<p>Output is managed for you.</p>","constraints":"<p>0 &lt;= Number of Nodes &lt;= 10^5 -1000 &lt;= value of Node data &lt;= 1000</p>","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\n#include <queue>\r\nusing namespace std;\r\n\r\nclass TreeNode\r\n{\r\npublic:\r\n int val = 0;\r\n TreeNode* left = nullptr;\r\n TreeNode* right = nullptr;\r\n\r\n TreeNode(int val)\r\n {\r\n this->val = val;\r\n }\r\n};\r\n\r\nvector<int> morrisInTraversal(TreeNode* root) {\r\n\r\n}\r\n\r\n// input_section=================================================\r\n\r\nTreeNode* createTree(vector<int>& arr, vector<int>& IDX)\r\n{\r\n\r\n if (IDX > arr.size() || arr[IDX] == -1)\r\n {\r\n IDX++;\r\n return nullptr;\r\n }\r\n\r\n TreeNode* node = new TreeNode(arr[IDX++]);\r\n node->left = createTree(arr, IDX);\r\n node->right = createTree(arr, IDX);\r\n\r\n return node;\r\n}\r\n\r\nvoid solve()\r\n{\r\n int n;\r\n cin >> n;\r\n vector<int> arr(n, 0);\r\n for (int i = 0; i < n; i++)\r\n {\r\n cin >> arr[i];\r\n }\r\n\r\n vector<int> IDX(1, 0);\r\n TreeNode* root = createTree(arr, IDX);\r\n\r\n vector<int> ans = morrisInTraversal(root);\r\n\r\n for (int i : ans)\r\n {\r\n cout << i << \" \";\r\n }\r\n}\r\n\r\nint main()\r\n{\r\n solve();\r\n return 0;\r\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n public static Scanner scn = new Scanner(System.in);\r\n\r\n public static class TreeNode {\r\n int val = 0;\r\n TreeNode left = null;\r\n TreeNode right = null;\r\n\r\n TreeNode(int val) {\r\n this.val = val;\r\n }\r\n }\r\n\r\n public static ArrayList<Integer> morrisInTraversal(TreeNode Treenode) {\r\n return null;\r\n }\r\n\r\n // input_section=================================================\r\n\r\n public static TreeNode createTree(int[] arr, int[] IDX) {\r\n if (IDX > arr.length || arr[IDX] == -1) {\r\n IDX++;\r\n return null;\r\n }\r\n TreeNode Treenode = new TreeNode(arr[IDX++]);\r\n Treenode.left = createTree(arr, IDX);\r\n Treenode.right = createTree(arr, IDX);\r\n\r\n return Treenode;\r\n }\r\n\r\n public static void solve() {\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for (int i = 0; i < n; i++)\r\n arr[i] = scn.nextInt();\r\n\r\n int[] IDX = new int;\r\n TreeNode root = createTree(arr, IDX);\r\n\r\n ArrayList<Integer> ans = morrisInTraversal(root);\r\n for (Integer i : ans)\r\n System.out.print(i + \" \");\r\n\r\n }\r\n\r\n public static void main(String[] args) {\r\n solve();\r\n }\r\n}"},"python":{"code":"def main():\r\n # Code here"}},"points":10,"difficulty":"easy","sampleInput":"15\r\n4\r\n2\r\n1\r\n-1\r\n-1\r\n3\r\n-1\r\n-1\r\n6\r\n5\r\n-1\r\n-1\r\n7\r\n-1\r\n-1","sampleOutput":"1 2 3 4 5 6 7","questionVideo":"","hints":[],"associated":[{"id":"321a84d2-27d4-4778-b77d-5ab9968a903e","name":"inorder morris traversal in binary tree MCQ 03","slug":"inorder-morris-traversal-in-binary-tree-mcq-03","type":4},{"id":"52c2950f-57af-4924-86bc-e987d1370730","name":"inorder morris traversal in binary tree MCQ 01","slug":"inorder-morris-traversal-in-binary-tree-mcq-01","type":4},{"id":"70f061ed-74af-45c7-b933-99b7bc2c42b9","name":"inorder morris traversal in binary tree MCQ 02","slug":"inorder-morris-traversal-in-binary-tree-mcq-02","type":4},{"id":"8bb3b577-cd46-4700-81a7-761056f5dd6f","name":"Inorder Morris Traversal In Binary Tree","slug":"inorder-morris-traversal-in-binary-tree","type":3},{"id":"baf59701-44bc-4a6f-b172-73bd86946781","name":"inorder morris traversal in binary tree MCQ 04","slug":"inorder-morris-traversal-in-binary-tree-mcq-04","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"2e9df04c-be14-441c-9a18-8b5a8ca6596d","name":"Trees For Intermediate","slug":"trees-for-intermediate-9994","type":0},{"id":"5d920258-7952-4c8e-abd0-2bc78609cc79","name":"In Order Morris Traversal In Binarytree","slug":"in-order-morris-traversal-in-binarytree","type":1}],"next":{"id":"f2dad269-9cd1-44d1-8539-304277b7a806","name":"In Order Morris Traversal In Binarytree","type":0,"slug":"in-order-morris-traversal-in-binarytree-zqslw"},"prev":null}}` Editor

# In Order Morris Traversal In Binarytree

easy

1. Given a Binary Tree, return inorder Traversal of it. 2. For more Information watch given video link below.

## Constraints

0 <= Number of Nodes <= 10^5 -1000 <= value of Node data <= 1000

## Format

### Input

Input is managed for you.

### Output

Output is managed for you.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}15 4 2 1 -1 -1 3 -1 -1 6 5 -1 -1 7 -1 -1```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}1 2 3 4 5 6 7`

Discussions

Show Discussion

Related Resources 