{"id":24,"date":"2020-03-15T05:54:36","date_gmt":"2020-03-15T05:54:36","guid":{"rendered":"http:\/\/54.153.35.165\/feellikelearning\/?p=24"},"modified":"2020-03-15T09:28:36","modified_gmt":"2020-03-15T09:28:36","slug":"traversal","status":"publish","type":"post","link":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/","title":{"rendered":"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion"},"content":{"rendered":"\n<p>Binary in order traversal \u4e00\u822c\u662f\u5927\u591a\u6570\u4eba\u5b66\u4e60\u7684\u7b2c\u4e00\u4e2arecursion\u7b97\u6cd5\uff0c\u975e\u5e38\u7b80\u5355\uff0c3\u884c\u5c31\u80fd\u5199\u5b8c\u3002\u4f46\u8fd9\u5176\u5b9e\u662fcompiler\u5e2e\u6211\u4eec\u5199\u4e86\u5927\u90e8\u5206\u7684code\uff0c\u7ec3\u4e60\u4e0d\u7528recursion\u80fd\u66f4\u597d\u7684\u5e2e\u52a9\u6211\u4eec\u7406\u89e3under the cover\u53d1\u751f\u4e86\u4ec0\u4e48\u3002\u5982\u679c\u6ca1\u7ec3\u4e60\u8fc7\uff0c\u5176\u5b9e\u8fd8\u662f\u4e0d\u5bb9\u6613\u60f3\u5230\u548c\u5199\u5bf9\u7684\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u5982\u4e0b<\/p>\n\n\n\n<p>Java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.util.Stack;\nimport TreeNode;\n\npublic class BstTraversal {\n    public static void traversal(TreeNode root) {\n        if (root == null)  {\n            return;\n        }\n        Stack&lt;TreeNode> stack = new Stack&lt;>();\n        pushLeft(root, stack);\n        while (!stack.isEmpty()) {\n            TreeNode cur = stack.pop();\n            System.out.println(cur.val);\n            if (cur.right != null) {\n                pushLeft(cur.right, stack);\n            }\n        }\n    }\n\n    public static void pushLeft(TreeNode node, Stack&lt;TreeNode> stack) {\n        TreeNode cur = node;\n        while (cur != null) {\n            stack.push(cur);\n            cur = cur.left;\n        }\n    }\n\n    \/\/ test\n    public static void main(String[] args) {\n        TreeNode node1 = new TreeNode(1);\n        TreeNode node2 = new TreeNode(2);\n        TreeNode node3 = new TreeNode(3);\n        TreeNode node4 = new TreeNode(4);\n        TreeNode node5 = new TreeNode(5);\n        TreeNode node6 = new TreeNode(6);\n\n        node1.left = node2;\n        node1.right = node3;\n        node2.left = node4;\n        node2.right = node5;\n        node3.left = node6;\n\n        traversal(node1);\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2dTreeNode class\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TreeNode {\n    public int val;\n    public TreeNode left;\n    public TreeNode right;\n\n    public  TreeNode(int val) {\n        this.val = val;\n        left = null;\n        right = null;\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Binary in order traversal \u4e00\u822c\u662f\u5927\u591a\u6570\u4eba\u5b66\u4e60\u7684\u7b2c\u4e00\u4e2arecursion\u7b97\u6cd5\uff0c\u975e\u5e38\u7b80\u5355\uff0c3\u884c\u5c31\u80fd\u5199\u5b8c\u3002\u4f46\u8fd9\u5176\u5b9e\u662fcompiler\u5e2e\u6211\u4eec\u5199\u4e86\u5927\u90e8\u5206\u7684code\uff0c\u7ec3\u4e60\u4e0d\u7528recursion\u80fd\u66f4\u597d\u7684\u5e2e\u52a9\u6211\u4eec\u7406\u89e3under the cover\u53d1\u751f\u4e86\u4ec0\u4e48\u3002\u5982\u679c\u6ca1\u7ec3\u4e60\u8fc7\uff0c\u5176\u5b9e\u8fd8\u662f\u4e0d\u5bb9\u6613\u60f3\u5230\u548c\u5199\u5bf9\u7684\u3002 \u4ee3\u7801\u5982\u4e0b Java \u5176\u4e2dTreeNode class\u5982\u4e0b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion | Feel Like Learning<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion | Feel Like Learning\" \/>\n<meta property=\"og:description\" content=\"Binary in order traversal \u4e00\u822c\u662f\u5927\u591a\u6570\u4eba\u5b66\u4e60\u7684\u7b2c\u4e00\u4e2arecursion\u7b97\u6cd5\uff0c\u975e\u5e38\u7b80\u5355\uff0c3\u884c\u5c31\u80fd\u5199\u5b8c\u3002\u4f46\u8fd9\u5176\u5b9e\u662fcompiler\u5e2e\u6211\u4eec\u5199\u4e86\u5927\u90e8\u5206\u7684code\uff0c\u7ec3\u4e60\u4e0d\u7528recursion\u80fd\u66f4\u597d\u7684\u5e2e\u52a9\u6211\u4eec\u7406\u89e3under the cover\u53d1\u751f\u4e86\u4ec0\u4e48\u3002\u5982\u679c\u6ca1\u7ec3\u4e60\u8fc7\uff0c\u5176\u5b9e\u8fd8\u662f\u4e0d\u5bb9\u6613\u60f3\u5230\u548c\u5199\u5bf9\u7684\u3002 \u4ee3\u7801\u5982\u4e0b Java \u5176\u4e2dTreeNode class\u5982\u4e0b\" \/>\n<meta property=\"og:url\" content=\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant\" \/>\n<meta property=\"og:site_name\" content=\"Feel Like Learning\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-15T05:54:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-15T09:28:36+00:00\" \/>\n<meta name=\"author\" content=\"feellikelearning\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"feellikelearning\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant#article\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant\"},\"author\":{\"name\":\"feellikelearning\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"headline\":\"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion\",\"datePublished\":\"2020-03-15T05:54:36+00:00\",\"dateModified\":\"2020-03-15T09:28:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant\"},\"wordCount\":21,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant\",\"url\":\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant\",\"name\":\"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion | Feel Like Learning\",\"isPartOf\":{\"@id\":\"https:\/\/feellikelearning.com\/#website\"},\"datePublished\":\"2020-03-15T05:54:36+00:00\",\"dateModified\":\"2020-03-15T09:28:36+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/feellikelearning.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/feellikelearning.com\/#website\",\"url\":\"https:\/\/feellikelearning.com\/\",\"name\":\"Feel Like Learning\",\"description\":\"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230\",\"publisher\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/feellikelearning.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a\",\"name\":\"feellikelearning\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g\",\"caption\":\"feellikelearning\"},\"logo\":{\"@id\":\"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion | Feel Like Learning","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant","og_locale":"en_US","og_type":"article","og_title":"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion | Feel Like Learning","og_description":"Binary in order traversal \u4e00\u822c\u662f\u5927\u591a\u6570\u4eba\u5b66\u4e60\u7684\u7b2c\u4e00\u4e2arecursion\u7b97\u6cd5\uff0c\u975e\u5e38\u7b80\u5355\uff0c3\u884c\u5c31\u80fd\u5199\u5b8c\u3002\u4f46\u8fd9\u5176\u5b9e\u662fcompiler\u5e2e\u6211\u4eec\u5199\u4e86\u5927\u90e8\u5206\u7684code\uff0c\u7ec3\u4e60\u4e0d\u7528recursion\u80fd\u66f4\u597d\u7684\u5e2e\u52a9\u6211\u4eec\u7406\u89e3under the cover\u53d1\u751f\u4e86\u4ec0\u4e48\u3002\u5982\u679c\u6ca1\u7ec3\u4e60\u8fc7\uff0c\u5176\u5b9e\u8fd8\u662f\u4e0d\u5bb9\u6613\u60f3\u5230\u548c\u5199\u5bf9\u7684\u3002 \u4ee3\u7801\u5982\u4e0b Java \u5176\u4e2dTreeNode class\u5982\u4e0b","og_url":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant","og_site_name":"Feel Like Learning","article_published_time":"2020-03-15T05:54:36+00:00","article_modified_time":"2020-03-15T09:28:36+00:00","author":"feellikelearning","twitter_card":"summary_large_image","twitter_misc":{"Written by":"feellikelearning","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant#article","isPartOf":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant"},"author":{"name":"feellikelearning","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"headline":"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion","datePublished":"2020-03-15T05:54:36+00:00","dateModified":"2020-03-15T09:28:36+00:00","mainEntityOfPage":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant"},"wordCount":21,"commentCount":0,"publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant#respond"]}]},{"@type":"WebPage","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant","url":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant","name":"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion | Feel Like Learning","isPartOf":{"@id":"https:\/\/feellikelearning.com\/#website"},"datePublished":"2020-03-15T05:54:36+00:00","dateModified":"2020-03-15T09:28:36+00:00","breadcrumb":{"@id":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/feellikelearning.com\/index.php\/2020\/03\/15\/traversal\/?variant=zh-hant#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/feellikelearning.com\/"},{"@type":"ListItem","position":2,"name":"\u7ecf\u5178\u7b97\u6cd5 \u975e\u9012\u5f52\u904d\u5386\u4e8c\u53c9\u6811 binary tree in order traversal without recursion"}]},{"@type":"WebSite","@id":"https:\/\/feellikelearning.com\/#website","url":"https:\/\/feellikelearning.com\/","name":"Feel Like Learning","description":"\u7a0b\u5e8f\uff5c\u751f\u6d3b\uff5c\u5b66\u5230\u5c31\u662f\u8d5a\u5230","publisher":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/feellikelearning.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/91fb815bebebf166c217b5e3764d437a","name":"feellikelearning","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/72a1e86e9dcb0332e88bd7d54fd36c28?s=96&d=mm&r=g","caption":"feellikelearning"},"logo":{"@id":"https:\/\/feellikelearning.com\/#\/schema\/person\/image\/"},"url":"https:\/\/feellikelearning.com\/index.php\/author\/feellikelearning\/"}]}},"_links":{"self":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/24"}],"collection":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":3,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":37,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/posts\/24\/revisions\/37"}],"wp:attachment":[{"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feellikelearning.com\/index.php\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}