{"id":325,"date":"2011-10-24T14:20:00","date_gmt":"2011-10-24T06:20:00","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=325"},"modified":"2020-06-06T14:21:45","modified_gmt":"2020-06-06T06:21:45","slug":"%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84_%e6%95%b0%e7%bb%84%e4%b8%8e%e5%b9%bf%e4%b9%89%e8%a1%a8_%e7%9f%a9%e9%98%b5%e7%9a%84%e5%8d%81%e5%ad%97%e9%93%be%e8%a1%a8%e5%ad%98%e5%82%a8%e7%a8%80%e7%96%8f%e7%9f%a9","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=325","title":{"rendered":"\u6570\u636e\u7ed3\u6784_\u6570\u7ec4\u4e0e\u5e7f\u4e49\u8868_\u77e9\u9635\u7684\u5341\u5b57\u94fe\u8868\u5b58\u50a8\u7a00\u758f\u77e9\u9635\u76f8\u52a0"},"content":{"rendered":"\n<p>\u00a0 \u00a0 \u5341\u5b57\u94fe\u8868\u505a\u5b58\u50a8\u7ed3\u6784\u5b9e\u73b0\u77e9\u9635\u76f8\u52a0\uff0c\u8fd9\u4e2a\u529f\u80fd\u7b80\u5355\u7684\u7a0b\u5e8f\u8c03\u8bd5\u4e86N\u4e45\uff0c\u6570\u5ea6\u60f3\u653e\u5f03\uff0c\u4f46\u60f3\u60f3\u8fd8\u662f\u60f3\u575a\u6301\u4e86\u4e0b\u6765\uff0c\u6307\u9488\u8df3\u6765\u8df3\u53bb\u7684\u5feb\u628a\u6211\u8df3\u6655\u4e86\uff0c\u5404\u79cd\u7ec6\u8282\uff0c\u6bd4\u5982\u5220\u9664\u8282\u70b9\u540e\u8981\u4fee\u6539\u76f8\u5e94\u8282\u70b9\u7684\u6307\u9488\u4ee5\u786e\u4fdd\u80fd\u6b63\u5e38\u8f93\u51fa\u3002\u7ec8\u4e8e\u8c03\u901a\u4e86\uff0c\u4e00\u9053\u574e\u603b\u7b97\u8fc7\u53bb\u4e86\uff0c\u793a\u4f8b\u901a\u8fc7\u540e\u8fde\u52a0\u6ce8\u91ca\u7684\u52c7\u6c14\u90fd\u6ca1\u4e86\u3002\u7b97\u4e86\uff0c\u5148\u8d34\u51fa\u6765\u5427\u3002<\/p>\n\n\n\n<p>crosslist.h<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\nusing namespace std;\n\n#define ElemType int\n#define MAX_MATRIX_SIZE 20\n\nclass OLNode\n{\npublic:\n\tOLNode();\n\tint i, j;\n\tElemType e;\n\tOLNode *down, *right;\n};\n\nOLNode::OLNode()\n{\n\tdown = right = NULL;\n}\n\nclass CrossList\n{\npublic:\n\tCrossList();\n\tOLNode *lhead&#91;MAX_MATRIX_SIZE + 1];\n\tOLNode *uhead&#91;MAX_MATRIX_SIZE + 1];\n\tint mu, nu, tu;\n};\n\nCrossList::CrossList()\n{\n\tfor (int i = 0; i &lt; MAX_MATRIX_SIZE; i++)\n\t\tlhead&#91;i] = uhead&#91;i] = NULL;\n\tmu = nu = tu = 0;\n}\n\nclass Matrix\n{\npublic:\n\tvoid MatrixPlus(); \/\/\u63a5\u53e3\u51fd\u6570\nprivate:\n\tvoid GetMatrix(CrossList&amp;); \/\/\u5f97\u5230\u4e09\u5143\u7ec4\u77e9\u9635\u5e76\u5c06\u5176\u94fe\u63a5\u6210\u5341\u5b57\u94fe\u8868\n\tvoid PrintMatrix(CrossList&amp;); \/\/\u6253\u5370\u4e09\u5143\u7ec4\u77e9\u9635\n\tvoid Plus(CrossList&amp;, CrossList&amp;); \/\/\u5728\u5341\u5b57\u94fe\u8868\u4e0a\u5b9e\u73b0\u77e9\u9635\u76f8\u52a0\n};\n\nvoid Matrix::MatrixPlus() \/\/\u63a5\u53e3\u51fd\u6570\n{\n\tCrossList m, n;\n\tGetMatrix(m); \/\/\u5f97\u5230\u4e09\u5143\u7ec4\u77e9\u9635\u5e76\u5c06\u5176\u94fe\u63a5\u6210\u5341\u5b57\u94fe\u8868\n\tGetMatrix(n); \/\/\u5f97\u5230\u4e09\u5143\u7ec4\u77e9\u9635\u5e76\u5c06\u5176\u94fe\u63a5\u6210\u5341\u5b57\u94fe\u8868\n\tPrintMatrix(m); \/\/\u6253\u5370\u4e09\u5143\u7ec4\u77e9\u9635\n\tPrintMatrix(n); \/\/\u6253\u5370\u4e09\u5143\u7ec4\u77e9\u9635\n\tPlus(m, n); \/\/\u5728\u5341\u5b57\u94fe\u8868\u4e0a\u5b9e\u73b0\u77e9\u9635\u76f8\u52a0\n\tPrintMatrix(m); \/\/\u6253\u5370\u4e09\u5143\u7ec4\u77e9\u9635\n}\n\nvoid Matrix::GetMatrix(CrossList &amp;t) \/\/\u5f97\u5230\u4e09\u5143\u7ec4\u77e9\u9635\u5e76\u5c06\u5176\u94fe\u63a5\u6210\u5341\u5b57\u94fe\u8868\n{\n\tcout &lt;&lt; \"Please Input The Size Of The Matrix(m*n)\" &lt;&lt; endl;\n\tcin >> t.mu >> t.nu;\n\tcout &lt;&lt; \"Please Input Matrix With Increasing Order Of RowNumber\" &lt;&lt; endl\n\t\t\t&lt;&lt; \"rownum columnnum element\" &lt;&lt; endl &lt;&lt; endl;\n\tint i, j;\n\tElemType e;\n\tOLNode *newnode, *p, *keep;\n\twhile (cin >> i >> j >> e)\n\t{\n\t\tif (e != 0) \/\/\u5143\u7d20\u4e0d\u4e3a0\n\t\t{\n\t\t\tnewnode = new OLNode;\n\t\t\tnewnode->i = i;\n\t\t\tnewnode->j = j;\n\t\t\tnewnode->e = e;\n\t\t\tif ((p = t.lhead&#91;i]) == NULL) \/\/\u5de6\u8fde\n\t\t\t\tt.lhead&#91;i] = newnode;\n\t\t\telse\n\t\t\t{\n\t\t\t\twhile (p->right != NULL &amp;&amp; p->right->right->j &lt; j)\n\t\t\t\t\tp = p->right;\n\t\t\t\tif (p->right == NULL)\n\t\t\t\t\tp->right = newnode;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tkeep = p->right->right;\n\t\t\t\t\tp->right = newnode;\n\t\t\t\t\tnewnode->right = keep;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif ((p = t.uhead&#91;j]) == NULL) \/\/\u4e0a\u8fde\n\t\t\t\tt.uhead&#91;j] = newnode;\n\t\t\telse\n\t\t\t{\n\t\t\t\twhile (p->down != NULL &amp;&amp; p->down->down->j &lt; j)\n\t\t\t\t\tp = p->down;\n\t\t\t\tif (p->down == NULL)\n\t\t\t\t\tp->down = newnode;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tkeep = p->down->down;\n\t\t\t\t\tp->down = newnode;\n\t\t\t\t\tnewnode->down = keep;\n\t\t\t\t}\n\t\t\t}\n\t\t\tt.tu++;\n\t\t}\n\t}\n\tcin.clear();\n}\n\nvoid Matrix::Plus(CrossList &amp;m, CrossList &amp;n) \/\/\u5728\u5341\u5b57\u94fe\u8868\u4e0a\u5b9e\u73b0\u77e9\u9635\u76f8\u52a0\n{\n\tOLNode *pm, *pn, *pre, *insert, *keep, *hl&#91;MAX_MATRIX_SIZE];\n\tfor (int i = 1; i &lt;= m.mu; i++) \/\/\u904d\u5386\u4ece\u6240\u6709\u884c\n\t{\n\t\tpm = m.lhead&#91;i];\n\t\tpn = n.lhead&#91;i];\n\t\tpre = NULL;\n\t\tfor (int j = 0; j &lt; MAX_MATRIX_SIZE; j++)\n\t\t\thl&#91;j] = m.uhead&#91;j];\n\t\twhile (pn != NULL)\n\t\t{\n\t\t\t\/\/\u6a2a\u63d2\n\t\t\tif (pm == NULL || pm->j > pn->j)\n\t\t\t{\n\t\t\t\t\/\/new a copynode\n\t\t\t\tinsert = new OLNode;\n\t\t\t\tinsert->i = pn->i;\n\t\t\t\tinsert->j = pn->j;\n\t\t\t\tinsert->e = pn->e;\n\t\t\t\t\/\/insert\n\t\t\t\tif (pre == NULL)\n\t\t\t\t\tm.lhead&#91;i] = insert;\n\t\t\t\telse\n\t\t\t\t\tpre->right = insert;\n\t\t\t\tinsert->right = pm;\n\t\t\t\tpre = insert;\n\t\t\t\t\/\/\u7ad6\u63d2\n\t\t\t\tif (m.uhead&#91;insert->j] == NULL\n\t\t\t\t\t\t|| m.uhead&#91;insert->j]->i > insert->i)\n\t\t\t\t{\n\t\t\t\t\tinsert->down = m.uhead&#91;insert->j];\n\t\t\t\t\tm.uhead&#91;insert->j] = insert;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tinsert->down = hl&#91;insert->j]->down;\n\t\t\t\t\thl&#91;insert->j]->down = insert;\n\t\t\t\t}\n\t\t\t\thl&#91;insert->j] = insert;\n\t\t\t\tpn = pn->right;\n\t\t\t}\n\t\t\telse if (pm->j == pn->j)\n\t\t\t{\n\t\t\t\tpm->e += pn->e;\n\t\t\t\tif (pm->e == 0)\n\t\t\t\t{\n\t\t\t\t\tkeep = pm;\n\t\t\t\t\tif (pre == NULL)\n\t\t\t\t\t{\n\t\t\t\t\t\tm.lhead&#91;pm->i] = pm->right;\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tpre->right = pm->right;\n\t\t\t\t\t\tpre = pm;\n\t\t\t\t\t}\n\t\t\t\t\tpm = pm->right;\n\t\t\t\t\tdelete keep;\n\n\t\t\t\t}\n\t\t\t\tpn = pn->right;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tpre = pm;\n\t\t\t\tpm = pm->right;\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid Matrix::PrintMatrix(CrossList &amp;t) \/\/\u6253\u5370\u4e09\u5143\u7ec4\u77e9\u9635\n{\n\tOLNode *p;\n\tfor (int i = 1; i &lt;= t.mu; i++)\n\t{\n\t\tp = t.lhead&#91;i];\n\t\twhile (p != NULL)\n\t\t{\n\t\t\tcout &lt;&lt; p->i &lt;&lt; \" \" &lt;&lt; p->j &lt;&lt; \" \" &lt;&lt; p->e &lt;&lt; endl;\n\t\t\tp = p->right;\n\t\t}\n\t}\n\tcout &lt;&lt; endl;\n}\n<\/code><\/pre>\n\n\n\n<p>main.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include\"crosslist.h\"\n \nint main()\n{\n\tMatrix M;\n\tM.MatrixPlus();\n\tsystem(\"pause\");\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 \u5341\u5b57\u94fe\u8868\u505a\u5b58\u50a8\u7ed3\u6784\u5b9e\u73b0\u77e9\u9635\u76f8\u52a0\uff0c\u8fd9\u4e2a\u529f\u80fd\u7b80\u5355\u7684\u7a0b\u5e8f\u8c03\u8bd5\u4e86N\u4e45\uff0c\u6570\u5ea6\u60f3\u653e\u5f03\uff0c\u4f46\u60f3\u60f3\u8fd8\u662f\u60f3\u575a\u6301\u4e86\u4e0b\u6765\uff0c\u6307\u9488\u8df3\u6765\u8df3\u53bb\u7684\u5feb\u628a\u6211\u8df3\u6655\u4e86\uff0c\u5404\u79cd\u7ec6\u8282\uff0c\u6bd4\u5982\u5220\u9664\u8282\u70b9\u540e\u8981&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"http:\/\/www.wangkaixuan.tech\/?p=325\"> 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-325","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\/325","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=325"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/325\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=325"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}