{"id":656,"date":"2019-06-09T08:49:54","date_gmt":"2019-06-09T00:49:54","guid":{"rendered":"http:\/\/fankasy.xyz\/?p=656"},"modified":"2019-09-25T08:52:58","modified_gmt":"2019-09-25T00:52:58","slug":"noj1019-%e8%ae%a1%e7%ae%97%e4%ba%8c%e5%8f%89%e6%a0%91%e7%9a%84%e9%ab%98%e5%ba%a6%e5%92%8c%e7%bb%93%e7%82%b9%e6%95%b0","status":"publish","type":"post","link":"http:\/\/fankasy.xyz\/index.php\/2019\/06\/09\/noj1019-%e8%ae%a1%e7%ae%97%e4%ba%8c%e5%8f%89%e6%a0%91%e7%9a%84%e9%ab%98%e5%ba%a6%e5%92%8c%e7%bb%93%e7%82%b9%e6%95%b0\/","title":{"rendered":"NOJ1019 \u8ba1\u7b97\u4e8c\u53c9\u6811\u7684\u9ad8\u5ea6\u548c\u7ed3\u70b9\u6570"},"content":{"rendered":"<p>\u8fd9\u53ef\u771f\u591f\u70e6\u7684&#8230;<\/p>\n<pre>#include&lt;stdio.h&gt;\r\n#include&lt;stdlib.h&gt;\r\ntypedef char ElemType;\r\nint n=0;\r\ntypedef struct BinaryTreeNode\r\n{\r\n\tElemType Data;\r\n\tstruct BinaryTreeNode *lChild, *rChild;\r\n}BinaryTreeNode;\r\ntypedef BinaryTreeNode* BiTree;\r\ntypedef struct BinaryTree{\r\n\tBinaryTreeNode *root;\r\n}BinaryTree;\r\nvoid PreOrderTransverse(BiTree t)\r\n{\r\n\tif (t == NULL)\r\n\t\treturn;\r\n\tn++;\r\n\tprintf(\" %c\", t-&gt;Data);\r\n\tPreOrderTransverse(t-&gt;lChild);\r\n\tPreOrderTransverse(t-&gt;rChild);\r\n}\r\nvoid InOrderTransverse(BiTree t)\r\n{\r\n\tif (t == NULL)\r\n\t\treturn;\r\n\tInOrderTransverse(t-&gt;lChild);\r\n\tprintf(\" %c\", t-&gt;Data);\r\n\tInOrderTransverse(t-&gt;rChild);\r\n}\r\nvoid PostOrderTransverse(BiTree t)\r\n{\r\n\tif (t == NULL)\r\n\t\treturn;\r\n\tPostOrderTransverse(t-&gt;lChild);\r\n\tPostOrderTransverse(t-&gt;rChild);\r\n\tprintf(\" %c\", t-&gt;Data);\r\n}\r\nBinaryTreeNode* PreCreateBt(BinaryTreeNode *t)\r\n{\r\n\tchar ch;\r\n\tch = getchar();\r\n\tgetchar();\r\n\tif (ch == '#')\r\n\t\tt = NULL;\r\n\telse\r\n\t{\r\n\t\tt = (BinaryTreeNode*)malloc(sizeof(BinaryTreeNode));\r\n\t\tt-&gt;Data = ch;\r\n\t\tt-&gt;lChild = PreCreateBt(t-&gt;lChild);\r\n\t\tt-&gt;rChild = PreCreateBt(t-&gt;rChild);\r\n\t}\r\n\r\n\treturn t;\r\n}\r\nint Max(int a, int b)\r\n{\r\n\treturn a &gt;= b ? a : b;\r\n}\r\nint SizeH(BinaryTree Bt)\r\n{\r\n\treturn SizeofHigh(Bt.root);\r\n}\r\nint SizeofHigh(BinaryTreeNode *p)\r\n{\r\n\tif (p == NULL)\r\n\t\treturn 0;\r\n\tif (p-&gt;lChild == NULL &amp;&amp; p-&gt;rChild == NULL)\r\n\t\treturn 1;\r\n\treturn Max(SizeofHigh(p-&gt;lChild), SizeofHigh(p-&gt;rChild)) + 1;\r\n}\r\nint SizeL(BinaryTree Bt)\r\n{\r\n\treturn SizeofLeaf(Bt.root);\r\n}\r\nint SizeofLeaf(BinaryTreeNode *p)\r\n{\r\n\tif (!p)\r\n\t\treturn 0;\r\n\tif ((!(p-&gt;lChild)) &amp;&amp; (!(p-&gt;rChild)))\r\n\t\treturn 1;\r\n\treturn SizeofLeaf(p-&gt;lChild) + SizeofLeaf(p-&gt;rChild);\r\n}\r\nint main()\r\n{\r\n\tBinaryTree myTree;\r\n\tint n0, n1, n2,h;\r\n\tmyTree.root = NULL;\r\n\tmyTree.root = PreCreateBt(myTree.root);\r\n\tprintf(\"PreOrder:\");\r\n\tPreOrderTransverse(myTree.root);\r\n\tprintf(\"\\n\");\r\n\tprintf(\"InOrder:\");\r\n\tInOrderTransverse(myTree.root);\r\n\tprintf(\"\\n\");\r\n\tprintf(\"PostOrder:\");\r\n\tPostOrderTransverse(myTree.root);\r\n\tprintf(\"\\n\");\r\n\th = SizeH(myTree);\r\n\tprintf(\"%d\\n\", h);\r\n\tn0 = SizeL(myTree);\r\n\tif (h == 0)\r\n\t\tn0 = n1 = n2 = 0;\r\n\telse\r\n\t{\r\n\t\tn2 = n0 - 1;\r\n\t\tn1 = n - n0 - n2;\r\n\t}\r\n\t\tprintf(\"%d %d %d\\n\",n, n0,n1);\r\n\treturn 0;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u53ef\u771f\u591f\u70e6\u7684&#8230; #include&lt;stdio.h&gt; #include&lt;stdli [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/posts\/656"}],"collection":[{"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=656"}],"version-history":[{"count":0,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/posts\/656\/revisions"}],"wp:attachment":[{"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=656"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fankasy.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}