This article is in the study summary, welcome reprint but please specify Source: http://blog.csdn.net/pistolove/article/details/42876657
Given a binary tree, return the inorder traversal of its nodes ' values.
For example:
Given binary Tree {1,#,2,3} ,
1 2 / 3
Return [1,3,2] .
Note: Recursive solution is trivial, could do it iteratively?
Ideas:
(1) Test instructions for the middle sequence traversal binary tree. The traversal order is left-to-root, right.
(2) Considering that recursion is relatively simple, this article uses the idea of recursion to solve, because relatively simple here is not cumbersome, see the code below.
(3) Hope this article is helpful to you.
The algorithm code is implemented as follows:
/** * @author liqq */public list<integer> inordertraversal (TreeNode root) {list<integer> result = new Linkedli St<integer> (); if (root = null) {In_order (result, root.left); Result.add (Root.val); In_order (result, root.right) ;} return result;} private void In_order (list<integer> result, TreeNode Curr) {if (Curr! = null) {In_order (result, curr.left); result.a DD (curr.val); In_order (result, curr.right);}}
Binary Tree inorder Traversal