{"id":162,"date":"2021-09-01T14:51:49","date_gmt":"2021-09-01T06:51:49","guid":{"rendered":"http:\/\/www.gislxz.top\/?p=162"},"modified":"2021-09-02T17:31:54","modified_gmt":"2021-09-02T09:31:54","slug":"%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%ef%bc%884%ef%bc%89-%e7%a8%80%e7%96%8f%e7%9f%a9%e9%98%b5","status":"publish","type":"post","link":"https:\/\/www.gislxz.com\/index.php\/2021\/09\/01\/%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%ef%bc%884%ef%bc%89-%e7%a8%80%e7%96%8f%e7%9f%a9%e9%98%b5\/","title":{"rendered":"\u6570\u636e\u7ed3\u6784\uff084\uff09\u7a00\u758f\u77e9\u9635"},"content":{"rendered":"\n<p>\u77e9\u9635\u8fd9\u7ae0\u8fd8\u6709\u51e0\u79cd\u7279\u6b8a\u77e9\u9635\uff0c\u50cf\u5bf9\u79f0\u77e9\u9635\uff0c\u4e09\u89d2\u77e9\u9635\uff0c\u5e26\u72b6\u77e9\u9635\u8fd9\u79cd\u53ea\u9700\u8981\u8003\u8651\u4e00\u4e0b\u4e00\u7ef4\u6570\u7ec4\u7684\u6620\u5c04\u5173\u7cfb\u5c31\u884c\uff0c\u53ea\u6709\u7a00\u758f\u77e9\u9635\u9700\u8981\u91cd\u65b0\u63cf\u8ff0\u3002<\/p>\n\n\n\n<p>\u7a00\u758f\u77e9\u9635\u5c31\u662f\u5143\u7d20\u6570\u91cf\u8f83\u5c11\uff0c\u5982\u679c\u4f7f\u7528\u5e38\u89c4\u77e9\u9635\u6a21\u578b\u6d6a\u8d39\u7a7a\u95f4\u4e14\u8fd0\u7b97\u65f6\u6548\u7387\u8fc7\u5dee\u3002<\/p>\n\n\n\n<p>\u7a00\u758f\u77e9\u9635\u7684\u63cf\u8ff0\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u6570\u7ec4\uff0c\u6570\u7ec4\u63cf\u8ff0\u7684\u7ebf\u6027\u8868\uff0c\u94fe\u8868\u90fd\u53ef\u4ee5\u63cf\u8ff0\u4e14\u5404\u6709\u4f18\u7f3a\u70b9<\/p>\n\n\n\n<p>\u5148\u5199\u4e00\u4e2a\u7528\u6570\u7ec4\u63cf\u8ff0\u7684\uff0c\u6570\u7ec4\u63cf\u8ff0\u7b80\u5355\uff0c\u67e5\u8be2\u5feb\uff0c\u4f46\u4fee\u6539\u5143\u7d20\u65f6\u90fd\u9700\u8981\u6574\u4e2a\u91cd\u5199\u6570\u7ec4\uff0c\u6027\u80fd\u8f83\u5dee\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u5199\u4e00\u4e2a\u7ed3\u6784\u4f53\u7528\u6765\u5b58\u50a8\u6bcf\u4e2a\u5143\u7d20\u7684\u884c\u53f7\u5217\u53f7\u548c\u6570\u503c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template&lt;class T&gt;\/\/\u6a21\u677f\u51fd\u6570\nstruct element\n{\n\tint row, col;\/\/\u884c\u53f7\uff0c\u5217\u53f7\n\tT value;\/\/\u503c\n\tvoid swap(element&lt;T&gt; b) {\/\/\u590d\u5236\n\t\tcol = b.col;\n\t\trow = b.row;\n\t\tvalue=b.value;\n\t}\n};<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\u662f\u7a00\u758f\u77e9\u9635\u7684\u5b9a\u4e49<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template&lt;class T&gt;\nclass matrix_array\/\/\u57fa\u4e8e\u6570\u7ec4\u7684\u7a00\u758f\u77e9\u9635\n{\npublic:\n\tmatrix_array(int,int);\/\/\u6784\u9020\u51fd\u6570\n\tmatrix_array(T ** a, int r, int c);\/\/\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u6784\u9020\u5e76\u8d4b\u503c\n\tmatrix_array(const matrix_array&lt;T&gt;&amp;);\/\/\u590d\u5236\u5df2\u6709\u7684\u7a00\u758f\u77e9\u9635\n\t~matrix_array() { delete&#91;]ls; }\n\tvoid printout();\/\/\u6253\u5370\u77e9\u9635\n\tint getrows() { return rows; }\/\/\u8fd4\u56de\u884c\u6570\n\tint getcols() { return cols; }\/\/\u8fd4\u56de\u5217\u6570\n\tT** output();\/\/\u8f93\u51fa\u4e8c\u7ef4\u6570\u7ec4\n\tmatrix_array&lt;T&gt; transposition();\n\tmatrix_array&lt;T&gt; add(const matrix_array&lt;T&gt;&amp;);\n\tvoid change(int row, int col, T c_value);\nprotected:\n\tint rows, cols, num;\/\/\u884c\u6570\uff0c\u5217\u6570\uff0c\u5143\u7d20\u4e2a\u6570\n\telement&lt;T&gt; *ls;\/\/element\u6570\u7ec4\n};<\/code><\/pre>\n\n\n\n<p>\u9996\u5148\u662f\u6784\u9020\u51fd\u6570\uff0c\u4e00\u4e2a\u662f\u9ed8\u8ba4\u6784\u9020\uff0c\u4e00\u4e2a\u662f\u7528\u4e8c\u7ef4\u6570\u7ec4\u8d4b\u503c\uff0c\u4e00\u4e2a\u662f\u590d\u5236\u5df2\u6709\u7a00\u758f\u77e9\u9635<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u9ed8\u8ba4\u6784\u9020\u51fd\u6570\ntemplate&lt;class T&gt;\nmatrix_array&lt;T&gt;::matrix_array(int r, int c) {\/\/\u8f93\u5165\u884c\u53f7\u5217\u53f7\n\trows = r;\n\tcols = c;\n\tnum = 0;\/\/\u9ed8\u8ba4\u6ca1\u6709\u975e0\u5143\u7d20\n\tls = new element&lt;T&gt;&#91;0];\n}\n\n\/\/\u4f7f\u7528\u4e8c\u7ef4\u6570\u7ec4\u6784\u9020\ntemplate&lt;class T&gt;\nmatrix_array&lt;T&gt;::matrix_array(T ** a, int r, int c) {\/\/\u8f93\u5165\u4e8c\u7ef4\u6570\u7ec4\uff0c\u884c\u53f7\u548c\u5217\u53f7\n\trows = r;\n\tcols = c;\n\tint n = 0;\/\/\u8ba1\u7b97\u975e0\u5143\u7d20\u4e2a\u6570\n\tfor(int i=0;i&lt;r;i++)\n\t\tfor (int j = 0; j &lt; c; j++) {\n\t\t\tif (a&#91;i]&#91;j] != 0)\n\t\t\t\tn++;\n\t\t}\n\tnum = n;\n\tls = new element&lt;T&gt;&#91;num];\n\tn = 0;\n\tfor (int i = 0; i &lt; r; i++)\n\t\tfor (int j = 0; j &lt; c; j++) {\n\t\t\tif (a&#91;i]&#91;j] != 0){\n\t\t\t\tls&#91;n].row = i + 1;\/\/\u8f93\u5165\u884c\u53f7\uff0c\u4ece1\u5f00\u59cb\uff0c\u6240\u4ee5\u52a01\n\t\t\t\tls&#91;n].col = j + 1;\/\/\u8f93\u5165\u5217\u53f7\uff0c\u4ece1\u5f00\u59cb\uff0c\u6240\u4ee5\u52a01\n\t\t\t    ls&#91;n].value = a&#91;i]&#91;j];\/\/\u8f93\u5165\u503c\n\t\t\t\tn++;\n\t\t\t}\n\t\t}\n}\n\n\/\/\u6784\u9020\u51fd\u6570-\u590d\u5236\u5df2\u6709\u7a00\u758f\u77e9\u9635\ntemplate&lt;class T&gt;\nmatrix_array&lt;T&gt;::matrix_array(const matrix_array&lt;T&gt; &amp;m){\/\/\u590d\u5236\u5df2\u6709\u7a00\u758f\u77e9\u9635\n\trows = m.rows;\n\tcols = m.cols;\n\tnum = m.num;\n\tls = new element&lt;T&gt;&#91;num];\n\tfor (int i = 0; i &lt; num; i++) {\n             ls&#91;i].swap(m.ls&#91;i]);\n\t}\n}<\/code><\/pre>\n\n\n\n<p>\u4e0b\u9762\u5199\u4e00\u4e2a\u6253\u5370\u51fd\u6570\uff0c\u56fe\u65b9\u4fbf\u5c31\u4e0d\u5199\u91cd\u8f7d&lt;&lt;\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template&lt;class T&gt;\nvoid matrix_array&lt;T&gt;::printout() {\n\tint n = 0;\n\tfor (int i = 0; i &lt; rows; i++) {\n\t\tfor (int j = 0; j &lt; cols; j++) {\/\/\u53cc\u5c42\u5faa\u73af\u5224\u65ad\u77e9\u9635\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u975e0\n\t\t\tif ((i == ls&#91;n].row - 1) &amp;&amp; (j == ls&#91;n].col - 1))\n\t\t\t{\n\t\t\t\tcout &lt;&lt; ls&#91;n].value &lt;&lt; \" \";\n\t\t\t\tn++;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcout &lt;&lt; 0 &lt;&lt; \" \";\n\t\t\t}\n\t\t}\n\t\tcout &lt;&lt; endl;\n\t}\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\u7684\u6253\u5370\u51fd\u6570\u867d\u7136\u6e05\u6670\u6613\u61c2\uff0c\u4f46\u4e24\u5c42\u5faa\u73af\u4f7f\u5f97\u65f6\u95f4\u590d\u6742\u5ea6\u8fd8\u662fO(n^2)\uff0c\u867d\u7136\u6ca1\u6709\u521b\u7acb\u4e8c\u7ef4\u6570\u7ec4\u8282\u7701\u4e86\u7a7a\u95f4\uff0c\u4f46\u6ca1\u6709\u53d1\u6325\u51fa\u7a00\u758f\u6570\u7ec4\u7684\u6027\u80fd\u4f18\u52bf\uff0c\u4e0b\u9762\u91cd\u5199\u4e00\u4e2a\u6253\u5370\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template&lt;class T&gt;\nvoid matrix_array&lt;T&gt;::printout() {\n\tint pre_row = 1,  pre_col = 1;\/\/\u4e0a\u4e00\u4e2a\u975e\u96f6\u5143\u7d20\u7684\u884c\u53f7\uff0c\u5217\u53f7\n\tfor (int i = 0; i &lt; num; i++) {\/\/\u9010\u4e2a\u975e\u96f6\u5143\u7d20\u5904\u7406\n\t\tif (ls&#91;i].row - pre_row &gt; 0)\/\/\u5224\u65ad\u662f\u5426\u9700\u8981\u6362\u884c\n\t\t{\t\n\t\t\tfor (int m = 0; m &lt; cols - pre_col + 1;m++)\/\/\u8865\u8db3\u8fd9\u884c\u76840\n\t\t\t\tcout &lt;&lt; 0&lt;&lt; \" \";\n\t\t\tcout&lt;&lt;endl;\/\/\u6362\u884c\n\t\t\tpre_col = 1;\/\/\u91cd\u7f6e\u4e0a\u4e00\u4e2a\u975e\u96f6\u5143\u7d20\u7684\u5217\u53f7\n\t\t\tpre_row++;\/\/\u4e0a\u4e00\u4e2a\u975e\u96f6\u5143\u7d20\u7684\u884c\u53f7+1\n\t\t}\n\t\tfor (int k = 0; k &lt; ls&#91;i].row - pre_row; k++) {\/\/\u5148\u5224\u65ad\u5f53\u524d\u975e\u96f6\u5143\u7d20\u79bb\u4e0a\u4e2a\u975e\u96f6\u5143\u7d20\u5dee\u4e86\u51e0\u884c\uff0c\u5dee\u4e86\u4e24\u884c\u5c31\u8981\u8f93\u51fa\u4e00\u884c0\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\u8fd9\u91cc\u7684\u51cf1\u662f\u56e0\u4e3a\u4e0a\u4e00\u4e2a\u5faa\u73af\u5b9e\u5219\u662f\u5904\u7406\u7684\u5c31\u662f\u5dee1\u7684\u60c5\u51b5\n\t\t\tfor (int l = 0; l &lt; cols; l++)\/\/\u8f93\u51fa\u4e00\u63920\n\t\t\t\tcout &lt;&lt; 0 &lt;&lt; \" \";\n\t\t\tcout &lt;&lt; endl;\n\t\t}\n\t\tpre_row=ls&#91;i].row;\/\/\u66f4\u65b0pre_row;\n\t\tfor (int j = 0; j &lt; ls&#91;i].col-pre_col; j++) {\/\/\u8f93\u51fa\u4e24\u4e2a\u5143\u7d20\u4e2d\u95f4\u7684\u96f6\n\t\t\tcout &lt;&lt; 0 &lt;&lt; \" \";\n\t\t}\n\t\tcout &lt;&lt; ls&#91;i].value&lt;&lt;\" \";\n\t\tpre_col = ls&#91;i].col+1;\/\/\u8fd9\u91ccpre_col\u662fls&#91;i].col+1\u8981\u7279\u522b\u6ce8\u610f\uff0c\u56e0\u4e3a\u884c\u53f7\u548c\u5217\u53f7\u5904\u7406\u8fc7\u7a0b\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u5343\u4e07\u4e0d\u80fd\u60f3\u5f53\u7136\u3002\u884c\u53f7\u5dee\u4e00\u4e2a\u9700\u8981\u5904\u7406\uff0c\u5217\u53f7\u76f8\u5dee\u4e00\u4e2a\u7b49\u4e8e\u7d27\u8ddf\u7740\uff0c\u4e0d\u7528\u5904\u7406\n\t}\n\t\/\/\u6700\u540e\u4e0d\u80fd\u5fd8\u4e86\u5269\u4e0b\u76840\n\tfor (int i = 0; i &lt; cols - pre_col + 1; i++)\n\t\tcout &lt;&lt; 0 &lt;&lt;\" \";\n\tcout &lt;&lt; endl;\n\n\tfor (int i = 0; i &lt; rows - pre_row; i++) {\n\t\tfor (int l = 0; l &lt; cols; l++)\n\t\t\tcout &lt;&lt; 0 &lt;&lt; \" \";\n\t\tcout &lt;&lt; endl;\n\t}\n}\n<\/code><\/pre>\n\n\n\n<p>\u5199\u8fd9\u4e2a\u51fd\u6570\u65f6\u672c\u4ee5\u4e3a\u80fd5\u5206\u949f\u5199\u5b8c\uff0c\u7ed3\u679c\u6298\u817e\u4e86\u4e00\u4e2a\u591a\u5c0f\u65f6\uff0c\u81ea\u5df1\u8fd8\u662f\u592a\u83dc\u4e86\uff0c\u5f88\u591a\u5730\u65b9\u4e00\u5f00\u59cb\u6ca1\u6709\u8003\u8651\u5468\u5230\u3002<\/p>\n\n\n\n<p>\u5199\u8f93\u51fa\u51fd\u6570\u5c24\u5176\u8981\u5c0f\u5fc3\uff0c\u591a\u6d4b\u8bd5\uff0c\u5404\u79cd\u60c5\u51b5\u7684\u77e9\u9635\u90fd\u8981\u6d4b\u8bd5\uff0c\u6bd4\u5982\u4e00\u6574\u884c\u90fd\u662f0\uff0c\u5f00\u5934\u4e00\u884c\u662f0\uff0c\u6700\u540e\u4e00\u884c\u662f0\uff0c\u5404\u79cd\u7279\u6b8a\u60c5\u51b5\u90fd\u8981\u91cd\u70b9\u8003\u8651\uff0c\u8981\u4e0d\u7136\u540e\u9762\u5199\u5176\u4ed6\u8ba1\u7b97\u51fd\u6570\u4e00\u76f4\u51fa\u9519\uff0c\u5176\u5b9e\u662f\u8f93\u51fa\u51fd\u6570\u9519\u4e86\u5374\u5bdf\u89c9\u4e0d\u5230\uff0c\u6d6a\u8d39\u5927\u7b14\u65f6\u95f4\u3002<\/p>\n\n\n\n<p>\u4e4b\u540e\u662f\u4e00\u4e2a\u8fd4\u56de\u4e8c\u7ef4\u6570\u7ec4\u7684\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u8fd4\u56de\u4e8c\u7ef4\u6570\u7ec4\ntemplate&lt;class T&gt;\nT** matrix_array&lt;T&gt;::output() {\n\tT** r = new T * &#91;cols];\/\/\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\n\tfor (int i = 0; i &lt; rows; i++) {\n\t\tr&#91;i] = new T&#91;cols]{ 0 };\/\/\u6bcf\u884c\u751f\u6210\u5168\u662f0\u7684\u4e00\u7ef4\u6307\u9488\n\t}\n\tfor(int i=0;i&lt;num;i++){\n\t\tr&#91;ls&#91;i].row-1]&#91;ls&#91;i].col-1] = ls&#91;i].value;\/\/\u7ed9\u975e0\u5143\u7d20\u8d4b\u503c\n\t}\n\treturn r;\n}<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\u662f\u77e9\u9635\u8f6c\u7f6e\uff0c\u8f6c\u7f6e\u770b\u4e0a\u53bb\u5f88\u7b80\u5355\uff0c\u884c\u53f7\u5217\u53f7\u6362\u4e00\u4e0b\u5c31\u884c\uff0c\u4f46\u590d\u6742\u7684\u662f\u7a00\u758f\u77e9\u9635\u662f\u7528\u6570\u7ec4\u6309\u6a2a\u5411\u987a\u5e8f\u5b58\u50a8\u7684\uff0c\u76f4\u63a5\u884c\u53f7\u5217\u53f7\u4e92\u6362\u987a\u5e8f\u5c31\u9519\u4e86\uff0c\u6240\u4ee5\u8981\u5148\u6392\u4e2a\u5e8f\u3002\u8f6c\u7f6e\u540e\u884c\u5217\u4e92\u6362\uff0c\u6240\u4ee5\u6392\u5e8f\u65f6\u5217\u662f\u7b2c\u4e00\u7d22\u5f15\uff0c\u884c\u662f\u7b2c\u4e8c\u7d22\u5f15<\/p>\n\n\n\n<p>\u53cc\u5173\u952e\u8bcd\u6392\u5e8f\u5176\u5b9e\u8ddf\u4f46\u5173\u952e\u8bcd\u6392\u5e8f\u6ca1\u533a\u522b\uff0c\u5199\u4e00\u4e2a\u7ed3\u6784\u4f53\u7684\u5927\u5c0f\u6bd4\u8f83\u51fd\u6570\u5c31\u884c\uff0c\u6ce8\u610f\u5199\u4e24\u79cd\u4e0d\u540c\u4e3b\u952e\u7684\u6bd4\u8f83\u51fd\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template&lt;class T&gt;\/\/\u6a21\u677f\u51fd\u6570\nstruct element\n{\n\tint row, col;\/\/\u884c\u6570\uff0c\u5217\u6570\uff08\u4ece1\u5f00\u59cb\uff09\n\tT value;\n\tint compare(element&lt;T&gt; b) {\/\/\u53cc\u5173\u952e\u8bcd\u6bd4\u8f83\uff0c\u6309\u5148\u884c\u6570\u540e\u5217\u6570\u6bd4\u8f83\uff0c\u5c0f\u8fd4\u56de0\uff0c\u5927\u4e8e\u7b49\u4e8e\u8fd4\u56de1\n\t\tif (row &lt; b.row)\n\t\t\treturn 0;\n\t\telse if ((row == b.row) &amp;&amp; (col &lt; b.col))\n\t\t\treturn 0;\n\t\telse\n\t\t\treturn 1;\n\t}\n\tint compare_tr(element&lt;T&gt; b) {\/\/\u53cc\u5173\u952e\u8bcd\u6bd4\u8f83\uff0c\u6309\u5148\u5217\u6570\u540e\u884c\u6570\u6bd4\u8f83\uff0c\u5927\u8fd4\u56de1\n\t\tif (col &gt; b.col)\n\t\t\treturn 1;\n\t\telse if ((col == b.col) &amp;&amp; (row &gt; b.row))\n\t\t\treturn 1;\n\t\telse\n\t\t\treturn 0;\n\t}\n\tvoid swap(element&lt;T&gt; b) {\/\/\u590d\u5236\n\t\tcol = b.col;\n\t\trow = b.row;\n\t\tvalue=b.value;\n\t}\n\tvoid swap_tr(element&lt;T&gt; b) {\/\/\u8f6c\u7f6e\u590d\u5236\n\t\tcol = b.row;\n\t\trow = b.col;\n\t\tvalue = b.value;\n\t}\n};<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\u901a\u8fc7\u7b80\u5355\u7684\u5192\u6ce1\u6392\u5e8f\u5f97\u51fa\u8f6c\u7f6e\u540e\u7684\u5143\u7d20\u7684\u6b63\u786e\u987a\u5e8f\u3002\u8fd9\u91cc\u7528\u4e86\u4e00\u4e2aindex\u6570\u7ec4\u6765\u6392\u5e8f\uff0c\u5c31\u4e0d\u7528\u590d\u5236\u4e00\u4e2aelement\u6570\u7ec4\u8fdb\u884c\u6392\u5e8f\u4e86<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u8f6c\u7f6e\ntemplate&lt;class T&gt;\nmatrix_array&lt;T&gt; matrix_array&lt;T&gt;::transposition(){\n\tint temp;\n\tint *index = new int&#91;num];\/\/index\u6570\u7ec4\uff0c\u7528\u6765\u6392\u5e8f\n\tfor (int i = 0; i &lt; num; i++) index&#91;i] = i;\n\tfor(int i=0;i&lt;num;i++)\/\/\u5bf9index\u8fdb\u884c\u6392\u5e8f\n\t\tfor (int j = 0; j &lt; num - 1; j++) {\/\/\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\n\t\t\tif (ls&#91;index&#91;j]].compare(ls&#91;index&#91;j + 1]])) {temp = index&#91;j + 1]; index&#91;j + 1] = index&#91;j]; index&#91;j] = temp; }\n\t\t}\n\tmatrix_array&lt;T&gt; res(cols, rows);\n\tres.num = num;\n\tres.ls = new element&lt;T&gt;&#91;num];\n\tfor (int i = 0; i &lt; num; i++) {\n\t\tres.ls&#91;i].swap_tr(ls&#91;index&#91;i]]);\n\t}\n\treturn res;\n}<\/code><\/pre>\n\n\n\n<p>\u5230\u73b0\u5728\u6211\u4eec\u7684\u77e9\u9635\u8fd8\u662f\u9759\u6001\u7684\uff0c\u4e0b\u9762\u5b9e\u73b0\u5bf9\u77e9\u9635\u5143\u7d20\u7684\u4fee\u6539<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u4fee\u6539\u5143\u7d20\ntemplate&lt;class T&gt;\nvoid matrix_array&lt;T&gt;::change(int row, int col, T c_value) {\n\telement&lt;T&gt; new_element;\/\/\u521b\u5efa\u65b0\u5143\u7d20\u5e76\u8d4b\u503c\n\tnew_element.row = row;\n\tnew_element.col = col;\n\tnew_element.value = c_value;\n\tif ((new_element.compare(ls&#91;0]) == 0)&amp;&amp;(c_value!=0))\/\/\u9996\u5148\u5224\u65ad\u65b0\u5143\u7d20\u662f\u5426\u5728\u539f\u6709\u7b2c\u4e00\u4e2a\u5143\u7d20\u524d\uff1f\n\t{\n\t\telement&lt;T&gt;* temp = new element&lt;T&gt;&#91;++num];\n\t\ttemp&#91;0].swap(new_element);\/\/\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e3a\u65b0\u5143\u7d20\n\t\tfor (int i = 1; i &lt; num; i++)\n\t\t\ttemp&#91;i].swap(ls&#91;i - 1]);\/\/\u540e\u9762\u4f9d\u6b21\u590d\u5236\u539f\u6570\u7ec4\n\t\tdelete&#91;]ls;\/\/\u5220\u9664\u539f\u8868\n\t\tls = temp;\/\/\u6307\u5411\u65b0\u8868\n\t}\n\telse{\n\t\tfor (int i = 0; i &lt; num; i++) {\n\t\t\tif (ls&#91;i].row == row &amp;&amp; ls&#91;i].col == col) {\/\/\u5224\u65ad\u662f\u5426\u4e0e\u5df2\u6709\u5143\u7d20\u5750\u6807\u76f8\u540c\uff1f\n\t\t\t\tif (c_value != 0)\/\/\u5982\u679c\u4fee\u6539\u540e\u7684\u503c\u4e0d\u7b49\u4e8e0,\u5c31\u53ea\u4fee\u6539\u503c\n\t\t\t\t\tls&#91;i].value = c_value;\n\t\t\t\telse if (c_value == 0) {\/\/\u5982\u679c\u4fee\u6539\u540e\u7684\u503c\u4e3a0\uff0c\u5c31\u5220\u9664\u5f53\u524d\u5143\u7d20\n\t\t\t\t\telement&lt;T&gt;* temp = new element&lt;T&gt;&#91;--num];\/\/\u65b0\u5efaelement\u6570\u7ec4\uff0c\u957f\u5ea6\u51cf\u4e00\n\t\t\t\t\t\/\/\u590d\u5236\u539f\u6709\u5143\u7d20\uff0c\u5220\u9664\u4fee\u6539\u5143\u7d20\n\t\t\t\t\tfor (int j = 0; j &lt; i; j++) {\n\t\t\t\t\t\ttemp&#91;j].swap(ls&#91;j]);\n\t\t\t\t\t}\n\t\t\t\t\tfor (int j = i; j &lt; num; j++) {\n\t\t\t\t\t\ttemp&#91;j].swap(ls&#91;j + 1]);\n\t\t\t\t\t}\n\t\t\t\t\tdelete&#91;]ls;\/\/\u5220\u9664\u539f\u6570\u7ec4\n\t\t\t\t\tls = temp;\/\/\u91cd\u65b0\u6307\u5411\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (i &lt; num - 1) {\/\/\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5355\u72ec\u5224\u65ad\n\t\t\t\tif ((new_element.compare(ls&#91;i]) == 1) &amp;&amp; (new_element.compare(ls&#91;i + 1])==0)) {\/\/\u662f\u5426\u5728\u4e24\u4e2a\u5df2\u6709\u5143\u7d20\u4e4b\u95f4\uff1f\n\t\t\t\t\telement&lt;T&gt;* temp = new element&lt;T&gt;&#91;++num];\n\t\t\t\t\tfor (int j = 0; j &lt; i+1; j++)\n\t\t\t\t\t\ttemp&#91;j].swap(ls&#91;j]);\n\t\t\t\t\ttemp&#91;i+1].swap(new_element);\n\t\t\t\t\tfor (int j = i + 2 ; j &lt; num; j++)\n\t\t\t\t\t\ttemp&#91;j].swap(ls&#91;j-1]);\n\t\t\t\t\tdelete&#91;]ls;\n\t\t\t\t\tls = temp;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif((new_element.compare(ls&#91;num]) == 1)&amp;&amp;(c_value)!=0)\/\/\u5224\u65ad\u65b0\u5143\u7d20\u662f\u5426\u5728\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u540e\uff1f\n\t{\n\t\telement&lt;T&gt;* temp = new element&lt;T&gt;&#91;++num];\n\t\tfor (int i = 0; i &lt; num-1; i++)\n\t\t\ttemp&#91;i].swap(ls&#91;i]);\/\/\u4f9d\u6b21\u590d\u5236\u539f\u6570\u7ec4\n\t\ttemp&#91;num - 1].swap(new_element);\n\t\tdelete&#91;]ls;\/\/\u5220\u9664\u539f\u8868\n\t\tls = temp;\/\/\u6307\u5411\u65b0\u8868\n\t}\n}<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\u662f\u77e9\u9635\u76f8\u52a0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*---------------\u77e9\u9635\u76f8\u52a0------------------------*\/\ntemplate&lt;class T&gt;\nmatrix_array&lt;T&gt; matrix_array&lt;T&gt;::add(const matrix_array&lt;T&gt;&amp; m) {\n\tif (m.cols != cols || m.rows != rows) {\/\/\u68c0\u67e5\u77e9\u9635\u5927\u5c0f\u662f\u5426\u76f8\u540c\n\t\tcout &lt;&lt; \"\u77e9\u9635\u5927\u5c0f\u4e0d\u5339\u914d\" &lt;&lt; endl;\n\t\tabort();\n\t}\n\telement&lt;T&gt;* add_element = new element&lt;T&gt;&#91;m.num + num];\/\/\u7ed3\u679c\u6700\u957f\u4e0d\u4f1a\u8d85\u8fc7\u539f\u6765\u4e24\u4e2a\u77e9\u9635\u6709\u6548\u5143\u7d20\u4e2a\u6570\u4e4b\u548c\n\tint i1 = 0, i2 = 0, i3 = 0;\/\/\u8bbe\u7f6e\u4e09\u4e2a\u7d22\u5f15\uff0c\u5206\u522b\u4e3a\u5f53\u524d\u77e9\u9635\u975e\u96f6\u5143\u7d20\uff0cm\u77e9\u9635\u7684\u975e\u96f6\u5143\u7d20\uff0c\u7ed3\u679c\u975e\u96f6\u5143\u7d20\u6570\u7ec4add_element\u7684\u7d22\u5f15\n\twhile (1) {\n\t\tif ((i1 == num) &amp;&amp; (i2 == m.num)) break;\/\/\u540c\u65f6\u8fed\u4ee3\u5230\u4e86\u4e24\u4e2a\u77e9\u9635\u6700\u540e\u4e00\u4e2a\u975e\u96f6\u5143\u7d20\n\t\tif (i1 == num) {\/\/\u7b2c\u4e00\u4e2a\u77e9\u9635\u7684\u975e\u96f6\u5143\u7d20\u5148\u8fed\u4ee3\u5230\u5e95\u4e86\n\t\t\tfor (int i = 0; i &lt; m.num - i2; i++) {\n\t\t\t\tadd_element&#91;i3].swap(m.ls&#91;i2]);\n\t\t\t\ti2++; i3++; break;\n\t\t\t}\n\t\t}\n\t\tif (i2 == m.num) {\/\/\u7b2c\u4e8c\u4e2a\u77e9\u9635\u7684\u975e\u96f6\u5143\u7d20\u5148\u8fed\u4ee3\u5230\u5e95\u4e86\n\t\t\tfor (int i = 0; i &lt; num - i1; i++) {\n\t\t\t\tadd_element&#91;i3].swap(ls&#91;i1]);\n\t\t\t\ti1++; i3++; break;\n\t\t\t}\n\t\t}\n\t\tif (ls&#91;i1].compare(m.ls&#91;i2]) == 2) {\/\/\u5f53\u524d\u8fed\u4ee3\u5230\u7684\u4e24\u4e2a\u77e9\u9635\u7d22\u5f15\u5728\u76f8\u540c\u4f4d\u7f6e\n\t\t\tif (ls&#91;i1].value + m.ls&#91;i2].value != 0) {\/\/\u76f8\u52a0\u540e\u4e0d\u7b49\u4e8e0\u5c31\u6dfb\u52a0\u65b0\u5143\u7d20\n\t\t\t\tadd_element&#91;i3].col = ls&#91;i1].col;\n\t\t\t\tadd_element&#91;i3].row = ls&#91;i1].row;\n\t\t\t\tadd_element&#91;i3].value = ls&#91;i1].value + m.ls&#91;i2].value;\n\t\t\t\ti3++;\n\t\t\t}\n\t\t\ti1++; i2++; continue;\/\/\u76f8\u52a0\u540e\u7b49\u4e8e0\u5c31\u4e0d\u6dfb\u52a0\u65b0\u5143\u7d20\uff0c\u4e24\u4e2a\u7d22\u5f15\u8fed\u4ee3\u4e00\u6b21\n\t\t}\n\t\t\/\/\u54ea\u4e2a\u7d22\u5f15\u4f4d\u7f6e\u5728\u524d\u5c31\u6dfb\u52a0\u8fd9\u4e2a\u7d22\u5f15\u7684\u5143\u7d20\n\t\tif (ls&#91;i1].compare(m.ls&#91;i2]) == 0) {\n\t\t\tadd_element&#91;i3].swap(ls&#91;i1]);\n\t\t\ti1++; i3++; continue;\n\t\t}\n\t\tif (ls&#91;i1].compare(m.ls&#91;i2]) == 1) {\n\t\t\tadd_element&#91;i3].swap(m.ls&#91;i2]);\n\t\t\ti2++; i3++; continue;\n\t\t}\n\t}\n\tmatrix_array&lt;T&gt; res(rows, cols);\/\/\u65b0\u5efa\u7ed3\u679c\u77e9\u9635\n\tres.ls = new element&lt;T&gt;&#91; i3 ];\/\/\u8fed\u4ee3\u5b8ci3\u5c31\u662f\u975e0\u5143\u7d20\u7684\u4e2a\u6570\n\tres.num = i3;\n\tfor (int i = 0; i &lt; i3; i++)\n\t\tres.ls&#91;i].swap(add_element&#91;i]);\n\tdelete&#91;]add_element;\n\treturn res;\n}<\/code><\/pre>\n\n\n\n<p>\u77e9\u9635\u76f8\u4e58\u611f\u89c9\u5f88\u96be\uff0c\u4e0d\u60f3\u5199\u4e86\uff0c\u6e9c\u4e86<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"1024\" src=\"http:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/09\/123-732x1024.jpg\" alt=\"\" class=\"wp-image-169\" srcset=\"https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/09\/123-732x1024.jpg 732w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/09\/123-214x300.jpg 214w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/09\/123.jpg 750w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><figcaption>\u6e9c\u5566<\/figcaption><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e\u6570\u7ec4\u7684\u7a00\u758f\u77e9\u9635\u5b9e\u73b0<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[9,7,8],"class_list":["post-162","post","type-post","status-publish","format-standard","hentry","category-5","tag-c","tag-7","tag-8"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts\/162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/comments?post=162"}],"version-history":[{"count":9,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts\/162\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/media?parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/categories?post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/tags?post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}