{"id":314,"date":"2011-09-27T14:11:00","date_gmt":"2011-09-27T06:11:00","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=314"},"modified":"2020-06-06T14:13:47","modified_gmt":"2020-06-06T06:13:47","slug":"%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84_%e5%9b%be_%e9%82%bb%e6%8e%a5%e8%a1%a8%e5%81%9a%e5%ad%98%e5%82%a8%e7%bb%93%e6%9e%84%e5%ae%9e%e7%8e%b0%e6%b1%82%e6%97%a0%e5%90%91%e5%9b%be%e7%9a%84%e8%bf%9e%e9%80%9a","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=314","title":{"rendered":"\u6570\u636e\u7ed3\u6784_\u56fe_\u90bb\u63a5\u8868\u505a\u5b58\u50a8\u7ed3\u6784\u5b9e\u73b0\u6c42\u65e0\u5411\u56fe\u7684\u8fde\u901a\u5206\u91cf_C++\u5b9e\u73b0"},"content":{"rendered":"\n<p>\u8c03\u4e86\u4e00\u4e2a\u665a\u4e0a\u7ec8\u4e8e\u628a\u8fd9\u6bb5\u7a0b\u5e8f\u7ed9\u8c03\u901a\u4e86\uff0c\u539f\u6765\u5bf9\u5b69\u5b50\u5144\u5f1f\u94fe\u8868\u7684\u7406\u89e3\u6709\u70b9\u504f\u5dee\uff0c\u8fd8\u6709\u5c31\u662f\u5bf9\u9012\u5f52\u6709\u4e86\u8ddf\u6df1\u523b\u7684\u7406\u89e3\uff0c\u5f53\u7136\u6700\u5927\u7684\u6536\u83b7\u5c31\u662f\u53d1\u73b0\u7a0b\u5e8f\u4e2d\u9519\u8bef\u7684\u80fd\u529b\u8fdb\u4e00\u6b65\u63d0\u9ad8\uff0c\u501f\u52a9\u4e8eVisual Stdio\u8fd9\u4e2a\u5f3a\u5927\u7684\u7f16\u7a0b\u73af\u5883\uff0c\u53ef\u4ee5\u8ba9\u6211\u8fc5\u901f\u5730\u79ef\u7d2f\u7f16\u7a0b\u7ecf\u9a8c\uff0c\u5feb\u901f\u7684\u53d1\u73b0\u7a0b\u5e8f\u4e2d\u9690\u542b\u7684\u6f0f\u6d1e\uff0c\u800c\u4e14\u4ed6\u5f3a\u5927\u7684\u81ea\u5b9a\u4e49\u529f\u80fd\u4e5f\u8ba9\u7f16\u7a0b\u53d8\u5f97\u5f97\u5fc3\u5e94\u624b\u3002\u63a8\u8350\u4f7f\u7528\u3002\u3002\u3002<\/p>\n\n\n\n<p>head.h<\/p>\n\n\n\n<p><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#define MAX_VEX_NUM 20\nusing namespace std;\n\nclass NODE \/\/\u8bb0\u5f55\u5b69\u5b50\u7ed3\u70b9\u7684\u5e8f\u53f7\u7b49\u4fe1\u606f\n{\npublic:\n\tNODE();\n\tint child;\n\tNODE *next;\n};\n\nNODE::NODE()\n{\n\tchild = 0;\n\tnext = NULL;\n}\n\nclass VexNode \/\/\u8bb0\u5f55\u9876\u70b9\u4fe1\u606f\n{\npublic:\n\tVexNode();\n\tbool visited;\n\tchar vexname;\n\tNODE *firstchild;\n};\n\nVexNode::VexNode()\n{\n\tvisited = false;\n\tfirstchild = NULL;\n}\n\nclass VexBox \/\/\u50a8\u5b58\u56fe\u7684\u90bb\u63a5\u8868\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 CSTreeNode \/\/\u751f\u6210\u6811\u8282\u70b9\n{\npublic:\n\tCSTreeNode();\n\tchar name;\n\tCSTreeNode *lchild, *rsibling;\n};\n\nCSTreeNode::CSTreeNode()\n{\n\tlchild = rsibling = NULL;\n}\n\nclass Graph\n{\npublic:\n\tGraph();\n\tvoid ShowGraph(); \/\/\u63a5\u53e3\u51fd\u6570\nprivate:\n\tvoid GetVexList(); \/\/\u5f97\u5230\u9876\u70b9\u4fe1\u606f\n\tvoid GetChild(); \/\/\u5f97\u5230\u5404\u4e2a\u9876\u70b9\u7684\u5b69\u5b50\u4fe1\u606f\n\tvoid DFSForest();\n\tvoid DFSTree(int, CSTreeNode*);\n\tvoid Print(); \/\/\u8f93\u51fa\u56fe\u7684\u9876\u70b9\u5b69\u5b50\u4fe1\u606f\n\tvoid PrintTree();\n\tvoid InOrderPrintTree(CSTreeNode*); \/\/\u4e2d\u5e8f\u8f93\u51fa\u751f\u6210\u6811\n\tVexBox l; \/\/\u5b9a\u4e49\u4e00\u4e2a\u90bb\u63a5\u8868\n\tCSTreeNode *root; \/\/\u751f\u6210\u6811\u6839\n};\n\nGraph::Graph()\n{\n\troot = NULL;\n}\n\nvoid Graph::ShowGraph() \/\/\u63a5\u53e3\u51fd\u6570\n{\n\tcout &lt;&lt; \"ShowGraph Called !\" &lt;&lt; endl &lt;&lt; endl;\n\tGetVexList(); \/\/\u5f97\u5230\u9876\u70b9\u4fe1\u606f\n\tGetChild(); \/\/\u5f97\u5230\u5404\u4e2a\u9876\u70b9\u7684\u5b69\u5b50\u4fe1\u606f\n\tPrint(); \/\/\u8f93\u51fa\u90bb\u63a5\u8868\u4fe1\u606f\n\tDFSForest(); \/\/\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8be5\u56fe\u5e76\u5efa\u7acb\u8fde\u901a\u5206\u91cf\u7684\u751f\u6210\u68ee\u6797\n\tPrintTree(); \/\/\u8f93\u51fa\u5404\u8fde\u901a\u5206\u91cf\n}\n\nvoid Graph::GetVexList() \/\/\u5f97\u5230\u9876\u70b9\u4fe1\u606f\n{\n\tcout &lt;&lt; \"GetVexList Called !\" &lt;&lt; endl &lt;&lt; endl;\n\tcout &lt;&lt; \"Please Enter The Vertexes :\" &lt;&lt; endl &lt;&lt; endl;\n\tchar name;\n\twhile (cin >> name)\n\t{\n\t\tl.vexbox&#91;l.vexnum++].vexname = name;\n\t}\n\tcin.clear();\n}\n\nvoid Graph::GetChild() \/\/\u5f97\u5230\u5404\u4e2a\u9876\u70b9\u7684\u5b69\u5b50\u4fe1\u606f\n{\n\tcout &lt;&lt; \"GetChild Called !\" &lt;&lt; endl &lt;&lt; endl;\n\tint num;\n\tNODE *p, *newnode;\n\tfor (int i = 0; i &lt; l.vexnum; i++)\n\t{\n\t\tcout &lt;&lt; \"Input The Children Of VerTex \" &lt;&lt; l.vexbox&#91;i].vexname &lt;&lt; \" : \"\n\t\t\t\t&lt;&lt; endl &lt;&lt; endl;\n\t\twhile (cin >> num)\n\t\t{\n\t\t\tnewnode = new NODE;\n\t\t\tnewnode->child = num;\n\t\t\tif ((p = l.vexbox&#91;i].firstchild) == NULL)\n\t\t\t{\n\t\t\t\tl.vexbox&#91;i].firstchild = newnode;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\twhile (p->next != NULL)\n\t\t\t\t{\n\t\t\t\t\tp = p->next;\n\t\t\t\t}\n\t\t\t\tp->next = newnode;\n\t\t\t}\n\t\t}\n\t\tcin.clear();\n\t}\n}\n\nvoid Graph::Print() \/\/\u8f93\u51fa\u90bb\u63a5\u8868\u4fe1\u606f\n{\n\tcout &lt;&lt; \"Print Called !\" &lt;&lt; endl &lt;&lt; endl;\n\tNODE *p;\n\tfor (int i = 0; i &lt; l.vexnum; i++)\n\t{\n\t\tp = l.vexbox&#91;i].firstchild;\n\t\tcout &lt;&lt; l.vexbox&#91;i].vexname &lt;&lt; \" : \" &lt;&lt; endl;\n\t\twhile (p != NULL)\n\t\t{\n\t\t\tcout &lt;&lt; \"\\t\" &lt;&lt; l.vexbox&#91;p->child].vexname &lt;&lt; endl;\n\t\t\tp = p->next;\n\t\t}\n\t}\n}\n\nvoid Graph::DFSForest() \/\/\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8be5\u56fe\u5e76\u5efa\u7acb\u8fde\u901a\u5206\u91cf\u7684\u751f\u6210\u68ee\u6797\n{\n\tcout &lt;&lt; \"DFSForest Called !\" &lt;&lt; endl &lt;&lt; endl;\n\tCSTreeNode *p, *newnode;\n\tfor (int i = 0; i &lt; l.vexnum; i++) \/\/\u5bf9\u5217\u8868\u5185\u7684\u6240\u6709\u8282\u70b9\u8fdb\u884c\u904d\u5386\n\t{\n\t\tif (l.vexbox&#91;i].visited == false) \/\/\u5982\u679c\u672a\u88ab\u8bbf\u95ee\n\t\t{\n\t\t\tnewnode = new CSTreeNode; \/\/\u65b0\u5f00\u8f9f\u4e00\u4e2a\u8282\u70b9\n\t\t\tnewnode->name = l.vexbox&#91;i].vexname; \/\/\u5f53\u524d\u8282\u70b9\u540d\u5b57\u8d4b\u7ed9\u65b0\u7684\u8282\u70b9\n\t\t\tif (root == NULL) \/\/\u5982\u679croot\u672a\u6307\u5411\u4efb\u4f55\u8282\u70b9\n\t\t\t{\n\t\t\t\tp = root = newnode;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tp->rsibling = newnode; \/\/\u5426\u5219\u5c31\u628a\u65b0\u5f00\u8f9f\u7684\u8282\u70b9\u6302\u5728\u53f3\u5144\u5f1f\u4e0a\n\t\t\t\tp = p->rsibling; \/\/p\u6307\u5411\u65b0\u5f00\u8f9f\u7684\u8282\u70b9\n\t\t\t}\n\t\t\tDFSTree(i, p); \/\/\u4ee5p\u4e3a\u6839\u8282\u70b9\u5efa\u7acb\u65b0\u6811\n\t\t}\n\t}\n}\n\nvoid Graph::DFSTree(int i, CSTreeNode *t) \/\/\u5de6\u5b69\u5b50\u53f3\u5144\u5f1f,\u5de6\u5b69\u5b50\u53f3\u5144\u5f1f!!!\u5728\u8fd9\u7ea0\u7ed3\u4e86\u534a\u5929\n{\n\tbool first = true;\n\tl.vexbox&#91;i].visited = true; \/\/\u6807\u8bb0\u4e3a\u5df2\u8bbf\u95ee\n\tNODE *q = l.vexbox&#91;i].firstchild;\n\tCSTreeNode *newnode, *p;\n\twhile (q != NULL)\n\t{\n\t\tif (l.vexbox&#91;q->child].visited == false) \/\/\u5982\u679c\u672a\u88ab\u8bbf\u95ee\n\t\t{\n\t\t\tl.vexbox&#91;q->child].visited = true;\n\t\t\tnewnode = new CSTreeNode;\n\t\t\tnewnode->name = l.vexbox&#91;q->child].vexname;\n\t\t\tif (first) \/\/\u5b69\u5b50\n\t\t\t{\n\t\t\t\tt->lchild = newnode;\n\t\t\t\tp = newnode;\n\t\t\t\tfirst = false;\n\t\t\t}\n\t\t\telse \/\/\u5144\u5f1f\n\t\t\t{\n\t\t\t\tp->rsibling = newnode;\n\t\t\t\tp = p->rsibling;\n\t\t\t}\n\t\t\tDFSTree(q->child, newnode);\n\t\t}\n\t\tq = q->next;\n\t}\n}\n\nvoid Graph::PrintTree() \/\/\u8c03\u7528InOrderPrintTree()\u8f93\u51fa\u751f\u6210\u68ee\u6797\u7684\u76f8\u5173\u4fe1\u606f\n{\n\tcout &lt;&lt; \"PrintTree Called !\" &lt;&lt; endl &lt;&lt; endl;\n\tCSTreeNode *p = root;\n\twhile (p != NULL)\n\t{\n\t\tcout &lt;&lt; p->name;\n\t\tInOrderPrintTree(p->lchild);\n\t\tcout &lt;&lt; endl &lt;&lt; endl;\n\t\tp = p->rsibling;\n\t}\n}\n\nvoid Graph::InOrderPrintTree(CSTreeNode *t) \/\/\u9012\u5f52\u904d\u5386\u6bcf\u4e00\u68f5\u6811\n{\n\tif (t == NULL)\n\t\treturn;\n\tcout &lt;&lt; t->name;\n\tInOrderPrintTree(t->lchild);\n\tInOrderPrintTree(t->rsibling);\n}\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    Graph g;\n    g.ShowGraph();\n\tsystem(\"pause\");\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8c03\u4e86\u4e00\u4e2a\u665a\u4e0a\u7ec8\u4e8e\u628a\u8fd9\u6bb5\u7a0b\u5e8f\u7ed9\u8c03\u901a\u4e86\uff0c\u539f\u6765\u5bf9\u5b69\u5b50\u5144\u5f1f\u94fe\u8868\u7684\u7406\u89e3\u6709\u70b9\u504f\u5dee\uff0c\u8fd8\u6709\u5c31\u662f\u5bf9\u9012\u5f52\u6709\u4e86\u8ddf\u6df1\u523b\u7684\u7406\u89e3\uff0c\u5f53\u7136\u6700\u5927\u7684\u6536\u83b7\u5c31\u662f\u53d1\u73b0\u7a0b\u5e8f\u4e2d\u9519\u8bef\u7684\u80fd\u529b\u8fdb\u4e00\u6b65\u63d0\u9ad8\uff0c\u501f\u52a9\u4e8eV&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"http:\/\/www.wangkaixuan.tech\/?p=314\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/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-314","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\/314","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=314"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/314\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}