{"id":304,"date":"2011-10-10T14:04:28","date_gmt":"2011-10-10T06:04:28","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=304"},"modified":"2020-06-06T14:05:37","modified_gmt":"2020-06-06T06:05:37","slug":"%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84_%e5%9b%be_%e6%8b%93%e6%89%91%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=304","title":{"rendered":"\u6570\u636e\u7ed3\u6784_\u56fe_\u62d3\u6251\u6392\u5e8f"},"content":{"rendered":"\n<p>head.h<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\nusing namespace std;\n\n#define MAX_VEX_NUM 20\n\nclass ArcNode \/\/\u5f27\u8282\u70b9\n{\npublic:\n\tArcNode();\n\tint tailnode;\n\tArcNode *next;\n};\n\nArcNode::ArcNode()\n{\n\tnext = NULL;\n}\n\nclass VexNode \/\/\u9876\u70b9\u8282\u70b9\n{\npublic:\n\tVexNode();\n\tchar name;\n\tint indegree;\n\tArcNode *firstarc;\n};\n\nVexNode::VexNode()\n{\n\tindegree = 0;\n\tfirstarc = NULL;\n}\n\nclass VexBox \/\/\u9876\u70b9\u96c6\u5408\n{\npublic:\n\tVexBox();\n\tVexNode vexbox&#91;MAX_VEX_NUM];\n\tint vexnum;\n};\n\nVexBox::VexBox()\n{\n\tvexnum = 0;\n}\n\nclass TPSort \/\/\u62d3\u6251\u6392\u5e8f\u7c7b\n{\npublic:\n\tvoid GetTPSquence(); \/\/\u63a5\u53e3\u51fd\u6570\nprivate:\n\tvoid GetVex(); \/\/\u5f97\u5230\u9876\u70b9\u4fe1\u606f\n\tvoid GetArc(); \/\/\u5f97\u5230\u5f27\u4fe1\u606f\n\tvoid TPSorting(); \/\/\u62d3\u6251\u6392\u5e8f\n\tVexBox v;\n};\n\nvoid TPSort::GetTPSquence() \/\/\u63a5\u53e3\u51fd\u6570\n{\n\tGetVex(); \/\/\u5f97\u5230\u9876\u70b9\u4fe1\u606f\n\tGetArc(); \/\/\u5f97\u5230\u5f27\u4fe1\u606f\n\tTPSorting(); \/\/\u62d3\u6251\u6392\u5e8f\n}\n\nvoid TPSort::GetVex() \/\/\u5f97\u5230\u9876\u70b9\u4fe1\u606f\n{\n\tcout &lt;&lt; \"Please Input The Name Of Each Vertex :\" &lt;&lt; endl &lt;&lt; endl;\n\tchar name;\n\twhile (cin >> name)\n\t{\n\t\tv.vexbox&#91;v.vexnum++].name = name;\n\t}\n\tcin.clear();\n}\n\nvoid TPSort::GetArc() \/\/\u5f97\u5230\u5f27\u4fe1\u606f\n{\n\tcout &lt;&lt; \"Please Input The Tail And Head Of Each Arc :\" &lt;&lt; endl &lt;&lt; endl;\n\tint vex1, vex2;\n\tArcNode *newnode, *p;\n\twhile (cin >> vex1 >> vex2)\n\t{\n\t\tnewnode = new ArcNode;\n\t\tnewnode->tailnode = vex2;\n\t\tv.vexbox&#91;vex2].indegree++;\n\t\tif ((p = v.vexbox&#91;vex1].firstarc) == NULL)\n\t\t{\n\t\t\tv.vexbox&#91;vex1].firstarc = newnode;\n\t\t}\n\t\telse\n\t\t{\n\t\t\twhile (p->next != NULL)\n\t\t\t\tp = p->next;\n\t\t\tp->next = newnode;\n\t\t}\n\t}\n\tcin.clear();\n}\n\nvoid TPSort::TPSorting() \/\/\u62d3\u6251\u6392\u5e8f\n{\n\tint count = 0;\n\tbool find = false;\n\tArcNode *p;\n\twhile (1)\n\t{\n\t\tfor (int i = 0; i &lt; v.vexnum; i++)\n\t\t{\n\t\t\tif (v.vexbox&#91;i].indegree == 0) \/\/\u5220\u9664\u5165\u5ea6\u4e3a\u96f6\n\t\t\t{\n\t\t\t\tv.vexbox&#91;i].indegree--;\n\t\t\t\tcout &lt;&lt; v.vexbox&#91;i].name &lt;&lt; endl;\n\t\t\t\tfind = true;\n\t\t\t\tcount++;\n\t\t\t\tp = v.vexbox&#91;i].firstarc;\n\t\t\t\twhile (p != NULL) \/\/\u76f8\u5173\u9876\u70b9\u7684\u5165\u5ea6\u51cf\u4e00\n\t\t\t\t{\n\t\t\t\t\tv.vexbox&#91;p->tailnode].indegree--;\n\t\t\t\t\tp = p->next;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t} \/\/if\n\t\t} \/\/for\n\t\tif (find == false)\n\t\t\tbreak;\n\t\telse\n\t\t\tfind = false;\n\t} \/\/while\n\tif (count == v.vexnum)\n\t\tcout &lt;&lt; \"This Is A Acycline Graph :\" &lt;&lt; endl &lt;&lt; endl; \/\/\u65e0\u73af\u56fe\n\telse\n\t\tcout &lt;&lt; \"This Is A Cycling Graph :\" &lt;&lt; endl &lt;&lt; endl; \/\/\u6709\u73af\n} \/\/TPSorting\n<\/code><\/pre>\n\n\n\n<p>main.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include\"head.h\"\n \nint main()\n{\n\tTPSort tp;\n\ttp.GetTPSquence();\n\tsystem(\"pause\");\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>head.h main.cpp<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-304","post","type-post","status-publish","format-standard","hentry","category-06-02-"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=304"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/304\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=304"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}