{"id":2504,"date":"2024-11-10T11:11:39","date_gmt":"2024-11-10T03:11:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2504\/"},"modified":"2024-11-10T11:11:39","modified_gmt":"2024-11-10T03:11:39","slug":"%e5%86%92%e6%b3%a1%e6%8e%92%e5%ba%8f%e4%b8%ad%ef%bc%8c%e6%95%b0%e7%bb%84%e6%89%93%e5%8d%b0%e5%bc%82%e5%b8%b8%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88%e5%9c%a8%e5%85%83%e7%b4%a0%e4%ba%a4%e6%8d%a2%e5%89%8d","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2504\/","title":{"rendered":"\u5192\u6ce1\u6392\u5e8f\u4e2d\uff0c\u6570\u7ec4\u6253\u5370\u5f02\u5e38\uff1a\u4e3a\u4ec0\u4e48\u5728\u5143\u7d20\u4ea4\u6362\u524d\u540e\u6253\u5370\u6570\u7ec4\u65f6\uff0c\u7ed3\u679c\u4e0d\u4e00\u81f4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173077959180550.jpg\" class=\"aligncenter\" title=\"\u5192\u6ce1\u6392\u5e8f\u4e2d\uff0c\u6570\u7ec4\u6253\u5370\u5f02\u5e38\uff1a\u4e3a\u4ec0\u4e48\u5728\u5143\u7d20\u4ea4\u6362\u524d\u540e\u6253\u5370\u6570\u7ec4\u65f6\uff0c\u7ed3\u679c\u4e0d\u4e00\u81f4\uff1f\u63d2\u56fe\" alt=\"\u5192\u6ce1\u6392\u5e8f\u4e2d\uff0c\u6570\u7ec4\u6253\u5370\u5f02\u5e38\uff1a\u4e3a\u4ec0\u4e48\u5728\u5143\u7d20\u4ea4\u6362\u524d\u540e\u6253\u5370\u6570\u7ec4\u65f6\uff0c\u7ed3\u679c\u4e0d\u4e00\u81f4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728\u4e2d\uff0c\u6570\u7ec4\u6253\u5370\u5f02\u5e38<\/strong><\/p>\n<p>\u5728\u5c1d\u8bd5\u7f16\u5199\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5\u65f6\uff0c\u53d1\u73b0\u4e86\u4e00\u4e2a\u5947\u602a\u7684\u73b0\u8c61\u3002\u5728\u5143\u7d20\u4ea4\u6362\u524d\u548c\u4ea4\u6362\u540e\u6253\u5370\u6570\u7ec4\u65f6\uff0c\u6570\u7ec4\u7ed3\u6784\u51fa\u73b0\u4e86\u4e0d\u540c\u3002<\/p>\n<p>\u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>\/\/ \u5143\u7d20\u4ea4\u6362\u4f4d\u7f6e\u524d\u6253\u5370\nfunction bubbleSort(array) {\n    for (let i = 0; i &lt; array.length - 1; i++) {\n        for (let j = i + 1; j &lt; array.length; j++) {\n            if (array[j] &lt; array[i]) {\n                const oldArr = JSON.parse(JSON.stringify(array));\n                console.log(oldArr);\n\n                \/\/ [1, 3, 6, 3, 23, 1, 34]\n                \/\/ [1, 1, 6, 3, 23, 3, 34]\n                \/\/ [1, 1, 3, 6, 23, 3, 34]\n                \/\/ [1, 1, 3, 3, 23, 6, 34]\n                [array[i], array[j]] = [array[j], array[i]];\n            }\n        }\n    }\n}\n\n\/\/ \u5143\u7d20\u4ea4\u6362\u4f4d\u7f6e\u540e\u6253\u5370\nfunction bubbleSort(array) {\n    for (let i = 0; i &lt; array.length - 1; i++) {\n        for (let j = i + 1; j &lt; array.length; j++) {\n            if (array[j] &lt; array[i]) {\n                const oldArr = JSON.parse(JSON.stringify(array));\n                [array[i], array[j]] = [array[j], array[i]];\n\n                console.log(oldArr);\n            }\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u5143\u7d20\u4ea4\u6362\u524d\u6253\u5370\u65f6\uff0c\u6253\u5370\u51fa\u4ea4\u6362\u524d\u7684\u6570\u7ec4\uff1b\u800c\u5728\u5143\u7d20\u4ea4\u6362\u540e\u6253\u5370\u65f6\uff0c\u5374\u6253\u5370\u51fa\u4ea4\u6362\u540e\u7684\u6570\u7ec4\u3002<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u51fa\u73b0\u8fd9\u79cd\u73b0\u8c61\u7684\u539f\u56e0\u662f\uff0c\u5728\u4f7f\u7528\u89e3\u6784\u8d4b\u503c [] \u8c03\u6362\u5143\u7d20\u4f4d\u7f6e\u65f6\uff0c\u4f1a\u4ea7\u751f\u4e00\u4e2a\u8fd4\u56de\u503c\u3002\u5728\u672a\u7528\u5206\u53f7 ; \u9694\u5f00\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e2a\u8fd4\u56de\u503c\u88ab\u8d4b\u503c\u7ed9\u4e86 oldArr\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u5728\u5143\u7d20\u4ea4\u6362\u524d\u6253\u5370\u65f6\uff0coldArr \u5b58\u50a8\u7684\u662f\u4ea4\u6362\u524d\u7684\u6570\u7ec4\uff0c\u800c\u5728\u5143\u7d20\u4ea4\u6362\u540e\u6253\u5370\u65f6\uff0coldArr \u5b58\u50a8\u7684\u662f\u4ea4\u6362\u540e\u7684\u6570\u7ec4\uff0c\u5bfc\u81f4\u4e86\u4e24\u6b21\u6253\u5370\u51fa\u73b0\u4e0d\u540c\u7684\u7ed3\u679c\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u5728\u89e3\u6784\u8d4b\u503c\u540e\u52a0\u4e0a\u5206\u53f7\uff0c\u5c06\u8fd4\u56de\u503c\u4e0e\u8d4b\u503c\u8bed\u53e5\u5206\u5f00\uff0c\u4ece\u800c\u907f\u514d\u6b64\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e2d\uff0c\u6570\u7ec4\u6253\u5370\u5f02\u5e38\uff1a\u4e3a\u4ec0\u4e48\u5728\u5143\u7d20\u4ea4\u6362\u524d\u540e\u6253\u5370\u6570\u7ec4\u65f6\uff0c\u7ed3\u679c\u4e0d\u4e00\u81f4\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e2d\uff0c\u6570\u7ec4\u6253\u5370\u5f02\u5e38 \u5728\u5c1d\u8bd5\u7f16\u5199\u5192\u6ce1\u6392\u5e8f\u7b97\u6cd5\u65f6\uff0c\u53d1\u73b0\u4e86\u4e00\u4e2a\u5947\u602a\u7684\u73b0\u8c61\u3002\u5728\u5143\u7d20\u4ea4\u6362\u524d\u548c\u4ea4\u6362\u540e\u6253\u5370\u6570\u7ec4\u65f6\uff0c\u6570\u7ec4\u7ed3\u6784\u51fa\u73b0\u4e86\u4e0d\u540c\u3002 \u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a \/\/ \u5143\u7d20\u4ea4\u6362\u4f4d\u7f6e\u524d\u6253\u5370 function bubbleSort(array) { for (let i = 0; i &lt; array.length &#8211; 1; i++) { for (let j = i + 1; j &lt; array.length; j++) { if (array[j] &lt; array[i]) { const oldArr = JSON.parse(JSON.stringify(array)); console.log(oldArr); \/\/ [1, 3, 6, 3, 23, 1, 34] \/\/ [1, 1, 6, 3, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2504","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=2504"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2504\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}