{"id":45224,"date":"2023-12-11T15:05:13","date_gmt":"2023-12-11T07:05:13","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=45224"},"modified":"2023-12-11T15:05:13","modified_gmt":"2023-12-11T07:05:13","slug":"%e6%89%8b%e5%86%99%e4%bb%a3%e7%a0%81%ef%bc%9a%e9%80%9a%e8%bf%87%e5%89%8d%e5%ba%8f%e5%92%8c%e4%b8%ad%e5%ba%8f%e8%bf%98%e5%8e%9f%e4%ba%8c%e5%8f%89%e6%a0%91-2","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/%e6%89%8b%e5%86%99%e4%bb%a3%e7%a0%81%ef%bc%9a%e9%80%9a%e8%bf%87%e5%89%8d%e5%ba%8f%e5%92%8c%e4%b8%ad%e5%ba%8f%e8%bf%98%e5%8e%9f%e4%ba%8c%e5%8f%89%e6%a0%91-2\/","title":{"rendered":"\u624b\u5199\u4ee3\u7801\uff1a\u901a\u8fc7\u524d\u5e8f\u548c\u4e2d\u5e8f\u8fd8\u539f\u4e8c\u53c9\u6811"},"content":{"rendered":"<p>&#8220;`&#8221;                    \u53c2\u8003\u56de\u7b54\uff1a<\/p>\n<p>\/\/\u7b97\u6cd51<\/p>\n<p>&lt;pre&gt;&lt;code class=&quot;&quot;language-c&quot;&quot; lang=&quot;&quot;c&quot;&quot;&gt;#include &lt;iostream&gt;<br \/>\n#include &lt;fstream&gt;<br \/>\n#include &lt;string&gt;<br \/>\nstruct TreeNode<br \/>\n{<br \/>\nstruct TreeNode* left;<br \/>\nstruct TreeNode* right;<br \/>\nchar  elem;<br \/>\n};<\/p>\n<p>TreeNode* BinaryTreeFromOrderings(char* inorder, char* preorder, int length)<br \/>\n{<br \/>\nif(length == 0)<br \/>\n{<br \/>\nreturn NULL;<br \/>\n}<br \/>\nTreeNode* node = new TreeNode;<br \/>\nnode-&gt;elem = *preorder;<br \/>\nint rootIndex = 0;<br \/>\nfor(;rootIndex &lt; length; rootIndex++)<br \/>\n{<br \/>\nif(inorder[rootIndex] == *preorder)<br \/>\nbreak;<br \/>\n}<br \/>\nnode-&gt;left = BinaryTreeFromOrderings(inorder, preorder +1, rootIndex);<br \/>\nnode-&gt;right = BinaryTreeFromOrderings(inorder + rootIndex + 1, preorder + rootIndex + 1, length &#8211; (rootIndex + 1));<br \/>\nstd::cout&lt;&lt;node-&gt;elem&lt;&lt;std::endl;<br \/>\nfree(node);<br \/>\nreturn NULL;<br \/>\n}<br \/>\nint main(int argc, char** argv){<br \/>\nchar* pr=&quot;&quot;GDAFEMHZ&quot;&quot;;<br \/>\nchar* in=&quot;&quot;ADEFGHMZ&quot;&quot;; BinaryTreeFromOrderings(in, pr, 8); printf(&quot;&quot;\\n&quot;&quot;); return 0;}<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u00a0<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u53c2\u8003\u56de\u7b54\uff1a \/\/\u7b97\u6cd51 &lt;pre&gt;&lt;code class=&#038; [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-45224","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/45224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=45224"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/45224\/revisions"}],"predecessor-version":[{"id":45225,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/45224\/revisions\/45225"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=45224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=45224"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=45224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}