{"id":1718,"date":"2018-10-09T15:29:42","date_gmt":"2018-10-09T07:29:42","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=1718"},"modified":"2018-10-25T08:34:56","modified_gmt":"2018-10-25T00:34:56","slug":"%e4%b9%9d%e5%a4%a7%e5%9f%ba%e7%a1%80%e6%8e%92%e5%ba%8f%e6%80%bb%e7%bb%93%e4%b8%8e%e5%af%b9%e6%af%94","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/1718","title":{"rendered":"\u4e5d\u5927\u57fa\u7840\u6392\u5e8f\u603b\u7ed3\u4e0e\u5bf9\u6bd4"},"content":{"rendered":"<div class=\"blog-content-box\">\n<div class=\"article-header-box\">\n<div class=\"article-header\">\n<div class=\"article-title-box\"><\/div>\n<\/div>\n<\/div>\n<article>\n<div id=\"article_content\" class=\"article_content clearfix csdn-tracking-statistics\" data-pid=\"blog\" data-mod=\"popu_307\" data-dsm=\"post\">\n<div class=\"htmledit_views\">\n<p><a href=\"http:\/\/blog.csdn.net\/amazing7\/article\/details\/51603682\">http:\/\/blog.csdn.net\/amazing7\/article\/details\/51603682<\/a><\/p>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u4e00\u3001\u5bf9\u6bd4\u5206\u6790\u56fe<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/img-blog.csdn.net\/20160607144411150\" alt=\"\" width=\"1131\" height=\"590\" \/><\/div>\n<ul>\n<li>\u5747\u6309\u4ece\u5c0f\u5230\u5927\u6392\u5217<\/li>\n<li>k\u4ee3\u8868\u6570\u503c\u4e2d\u7684\u201d\u6570\u4f4d\u201d\u4e2a\u6570<\/li>\n<li>n\u4ee3\u8868\u6570\u636e\u89c4\u6a21<\/li>\n<li>m\u4ee3\u8868\u6570\u636e\u7684\u6700\u5927\u503c\u51cf\u6700\u5c0f\u503c<\/li>\n<\/ul>\n<blockquote><p>\u7a33\u5b9a\u6027\uff1a\u7a33\u5b9a\u6392\u5e8f\u7b97\u6cd5\u4f1a\u8ba9\u539f\u672c\u6709\u76f8\u7b49\u952e\u503c\u7684\u7eaa\u5f55\u7ef4\u6301\u76f8\u5bf9\u6b21\u5e8f\u3002\u4e5f\u5c31\u662f\u5982\u679c\u4e00\u4e2a\u6392\u5e8f\u7b97\u6cd5\u662f\u7a33\u5b9a\u7684\uff0c\u5f53\u6709\u4e24\u4e2a\u76f8\u7b49\u952e\u503c\u7684\u7eaa\u5f55R\u548cS\uff0c\u4e14\u5728\u539f\u672c\u7684\u5217\u8868\u4e2dR\u51fa\u73b0\u5728S\u4e4b\u524d\uff0c\u5728\u6392\u5e8f\u8fc7\u7684\u5217\u8868\u4e2dR\u4e5f\u5c06\u4f1a\u662f\u5728S\u4e4b\u524d\u3002<\/p><\/blockquote>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u4e8c\u3001\u5192\u6ce1\u6392\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"title\"><a target=\"_blank\" name=\"t0\"><\/a><\/h2>\n<h1 id=\"\u6982\u8ff0\"><a name=\"t1\"><\/a><a target=\"_blank\" name=\"t1\"><\/a>\u6982\u8ff0<\/h1>\n<p>\u5192\u6ce1\u6392\u5e8f\u901a\u8fc7\u91cd\u590d\u5730\u8d70\u8bbf\u8fc7\u8981\u6392\u5e8f\u7684\u6570\u5217\uff0c\u4e00\u6b21\u6bd4\u8f83\u4e24\u4e2a\u5143\u7d20\uff0c\u5982\u679c\u4ed6\u4eec\u7684\u987a\u5e8f\u9519\u8bef\u5c31\u628a\u4ed6\u4eec\u4ea4\u6362\u8fc7\u6765\uff0c\u76f4\u5230\u6ca1\u6709\u518d\u9700\u8981\u4ea4\u6362\u7684\u5143\u7d20\u4e3a\u6b62\uff08\u5bf9n\u4e2a\u9879\u76ee\u9700\u8981O(n^2)\u7684\u6bd4\u8f83\u6b21\u6570\uff09\u3002\u8fd9\u4e2a\u7b97\u6cd5\u7684\u540d\u5b57\u7531\u6765\u662f\u56e0\u4e3a\u8d8a\u5c0f\u7684\u5143\u7d20\u4f1a\u7ecf\u7531\u4ea4\u6362\u6162\u6162\u201c\u6d6e\u201d\u5230\u6570\u5217\u7684\u9876\u7aef\u3002<\/p>\n<h1 id=\"\u5b9e\u73b0\u6b65\u9aa4\"><a name=\"t2\"><\/a><a target=\"_blank\" name=\"t2\"><\/a>\u5b9e\u73b0\u6b65\u9aa4<\/h1>\n<ol>\n<li>\u6bd4\u8f83\u76f8\u90bb\u7684\u5143\u7d20\u3002\u5982\u679c\u7b2c\u4e00\u4e2a\u6bd4\u7b2c\u4e8c\u4e2a\u5927\uff0c\u5c31\u4ea4\u6362\u4ed6\u4eec\u4e24\u4e2a\u3002<\/li>\n<li>\u5bf9\u6bcf\u4e00\u5bf9\u76f8\u90bb\u5143\u7d20\u505a\u540c\u6837\u7684\u5de5\u4f5c\uff0c\u4ece\u5f00\u59cb\u7b2c\u4e00\u5bf9\u5230\u7ed3\u5c3e\u7684\u6700\u540e\u4e00\u5bf9\u3002\u8fd9\u6b65\u505a\u5b8c\u540e\uff0c\u6700\u540e\u7684\u5143\u7d20\u4f1a\u662f\u6700\u5927\u7684\u6570\u3002<\/li>\n<li>\u9488\u5bf9\u6240\u6709\u7684\u5143\u7d20\u91cd\u590d\u4ee5\u4e0a\u7684\u6b65\u9aa4\uff0c\u9664\u4e86\u6700\u540e\u4e00\u4e2a\u3002<\/li>\n<li>\u6301\u7eed\u6bcf\u6b21\u5bf9\u8d8a\u6765\u8d8a\u5c11\u7684\u5143\u7d20\u91cd\u590d\u4e0a\u9762\u7684\u6b65\u9aa4\uff0c\u76f4\u5230\u6ca1\u6709\u4efb\u4f55\u4e00\u5bf9\u6570\u5b57\u9700\u8981\u6bd4\u8f83\u3002<\/li>\n<\/ol>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160511102808244\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5192\u6ce1\u6392\u5e8f\u4e3a\u4e00\u5217\u6570\u5b57\u8fdb\u884c\u6392\u5e8f\u7684\u8fc7\u7a0b<\/p>\n<h1 id=\"\u5b9e\u73b0\u6027\u80fd\"><a name=\"t3\"><\/a><a target=\"_blank\" name=\"t3\"><\/a>\u5b9e\u73b0\u6027\u80fd<\/h1>\n<ul>\n<li>\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6<\/li>\n<\/ul>\n<blockquote><p>O(n^2)<\/p><\/blockquote>\n<ul>\n<li>\u6700\u4f18\u65f6\u95f4\u590d\u6742\u5ea6<\/li>\n<\/ul>\n<blockquote><p>O(n)<\/p><\/blockquote>\n<ul>\n<li>\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6<\/li>\n<\/ul>\n<blockquote><p>O(n^2)<\/p><\/blockquote>\n<ul>\n<li>\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6<\/li>\n<\/ul>\n<blockquote><p>\u603b\u5171O(n)\uff0c\u9700\u8981\u8f85\u52a9\u7a7a\u95f4O(1)<\/p><\/blockquote>\n<h1 id=\"java\u5b9e\u73b0\"><a name=\"t4\"><\/a><a target=\"_blank\" name=\"t4\"><\/a>Java\u5b9e\u73b0<\/h1>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cs has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;main&lt;\/span&gt;(String[] args) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] number = {&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;95&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;45&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;15&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;78&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;84&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;51&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;24&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;12&lt;\/span&gt;}; bubble_sort(number); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; i &lt; number.length; i++) { System.&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;out&lt;\/span&gt;.print(number[i] + &lt;span class=\"hljs-string\" style=\"color: rgb(0, 136, 0); box-sizing: border-box;\"&gt;\" \"&lt;\/span&gt;); } } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;bubble_sort&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] arr) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; temp, len = arr.length; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt; (&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; i &lt; len - &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; i++) &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt; (&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; j = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; j &lt; len - &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt; - i; j++) &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt; (arr[j] &gt; arr[j + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;]) { temp = arr[j]; arr[j] = arr[j + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;]; arr[j + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;] = temp; } }&lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u4e09\u3001\u9009\u62e9\u6392\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"title-1\"><a target=\"_blank\" name=\"t5\"><\/a><\/h2>\n<h1 id=\"\u9009\u62e9\u6392\u5e8f\"><a name=\"t6\"><\/a><a target=\"_blank\" name=\"t6\"><\/a>\u9009\u62e9\u6392\u5e8f<\/h1>\n<p>\u5e38\u7528\u7684\u9009\u62e9\u6392\u5e8f\u65b9\u6cd5\u6709\u7b80\u5355\u9009\u62e9\u6392\u5e8f\u548c\u5806\u6392\u5e8f\uff0c\u8fd9\u91cc\u53ea\u8bf4\u7b80\u5355\u9009\u62e9\u6392\u5e8f\uff0c\u5806\u6392\u5e8f\u540e\u9762\u518d\u8bf4\u3002<\/p>\n<h1 id=\"\u7b80\u5355\u9009\u62e9\u6392\u5e8f\"><a name=\"t7\"><\/a><a target=\"_blank\" name=\"t7\"><\/a>\u7b80\u5355\u9009\u62e9\u6392\u5e8f<\/h1>\n<p>\u8bbe\u6240\u6392\u5e8f\u5e8f\u5217\u7684\u8bb0\u5f55\u4e2a\u6570\u4e3an\uff0ci\u3000\u53d6\u30001,2,\u2026,n-1\u3000\u3002<br \/>\n\u4ece\u6240\u6709n-i+1\u4e2a\u8bb0\u5f55\uff08Ri,Ri+1,\u2026,Rn\uff09\u4e2d\u627e\u51fa\u6392\u5e8f\u7801\u6700\u5c0f\uff08\u6216\u6700\u5927\uff09\u7684\u8bb0\u5f55\uff0c\u4e0e\u7b2ci\u4e2a\u8bb0\u5f55\u4ea4\u6362\u3002\u6267\u884cn-1\u8d9f \u540e\u5c31\u5b8c\u6210\u4e86\u8bb0\u5f55\u5e8f\u5217\u7684\u6392\u5e8f\u3002<\/p>\n<p>\u4ee5\u6392\u5e8f\u6570\u7ec4\uff5b3\uff0c2\uff0c1\uff0c4\uff0c6\uff0c5\uff5d\u4e3a\u4f8b<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160511111047864\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160511111210100\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h1 id=\"\u7b80\u5355\u9009\u62e9\u6392\u5e8f\u6027\u80fd\"><a name=\"t8\"><\/a><a target=\"_blank\" name=\"t8\"><\/a>\u7b80\u5355\u9009\u62e9\u6392\u5e8f\u6027\u80fd<\/h1>\n<p>\u5728\u7b80\u5355\u9009\u62e9\u6392\u5e8f\u8fc7\u7a0b\u4e2d\uff0c\u6240\u9700\u79fb\u52a8\u8bb0\u5f55\u7684\u6b21\u6570\u6bd4\u8f83\u5c11\u3002\u6700\u597d\u60c5\u51b5\u4e0b\uff0c\u5373\u5f85\u6392\u5e8f\u8bb0\u5f55\u521d\u59cb\u72b6\u6001\u5c31\u5df2\u7ecf\u662f\u6b63\u5e8f\u6392\u5217\u4e86\uff0c\u5219\u4e0d\u9700\u8981\u79fb\u52a8\u8bb0\u5f55\u3002<br \/>\n\u6700\u574f\u60c5\u51b5\u4e0b\uff0c\u5373\u5f85\u6392\u5e8f\u8bb0\u5f55\u521d\u59cb\u72b6\u6001\u662f\u6309\u7b2c\u4e00\u6761\u8bb0\u5f55\u6700\u5927\uff0c\u4e4b\u540e\u7684\u8bb0\u5f55\u4ece\u5c0f\u5230\u5927\u987a\u5e8f\u6392\u5217\uff0c\u5219\u9700\u8981\u79fb\u52a8\u8bb0\u5f55\u7684\u6b21\u6570\u6700\u591a\u4e3a3\uff08n-1\uff09\u3002<\/p>\n<p>\u7b80\u5355\u9009\u62e9\u6392\u5e8f\u8fc7\u7a0b\u4e2d\u9700\u8981\u8fdb\u884c\u7684\u6bd4\u8f83\u6b21\u6570\u4e0e\u521d\u59cb\u72b6\u6001\u4e0b\u5f85\u6392\u5e8f\u7684\u8bb0\u5f55\u5e8f\u5217\u7684\u6392\u5217\u60c5\u51b5\u65e0\u5173\u3002<br \/>\n\u5f53i=1\u65f6\uff0c\u9700\u8fdb\u884cn-1\u6b21\u6bd4\u8f83\uff1b\u5f53i=2\u65f6\uff0c\u9700\u8fdb\u884cn-2\u6b21\u6bd4\u8f83\uff1b\u4f9d\u6b21\u7c7b\u63a8\uff0c\u5171\u9700\u8981\u8fdb\u884c\u7684\u6bd4\u8f83\u6b21\u6570\u662f(n-1)+(n-2)+\u2026+2+1=n(n-1)\/2\uff0c\u5373\u8fdb\u884c\u6bd4\u8f83\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n^2)\uff0c\u8fdb\u884c\u79fb\u52a8\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n)\u3002<\/p>\n<p>\u7b80\u5355\u9009\u62e9\u6392\u5e8f\u662f\u4e0d\u7a33\u5b9a\u6392\u5e8f\u3002<\/p>\n<h1 id=\"\u7b80\u5355\u9009\u62e9\u6392\u5e8fjava\u5b9e\u73b0\"><a name=\"t9\"><\/a><a target=\"_blank\" name=\"t9\"><\/a>\u7b80\u5355\u9009\u62e9\u6392\u5e8fJava\u5b9e\u73b0<\/h1>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cs has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;main&lt;\/span&gt;(String[] args) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] number = {&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;3&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;8&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;4&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;5&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;24&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;12&lt;\/span&gt;}; SimpleSort(number); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; i &lt; number.length; i++) { System.&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;out&lt;\/span&gt;.print(number[i] + &lt;span class=\"hljs-string\" style=\"color: rgb(0, 136, 0); box-sizing: border-box;\"&gt;\" \"&lt;\/span&gt;); } } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;SimpleSort&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] arr) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; length=arr.length; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; temp; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;;i&lt;length-&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;;i++){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; min=i; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; j=i+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;;j&lt;length;j++){ &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5bfb\u627e\u6700\u5c0f\u7684\u6570&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(arr[j]&lt;arr[min]){ min =j; } } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(min!=i){ temp = arr[min]; arr[min]=arr[i]; arr[i]=temp; } } } &lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;23&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;24&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u56db\u3001\u5e0c\u5c14\u6392\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"title-2\"><a target=\"_blank\" name=\"t10\"><\/a><\/h2>\n<h1 id=\"\u6982\u8ff0-1\"><a name=\"t11\"><\/a><a target=\"_blank\" name=\"t11\"><\/a>\u6982\u8ff0<\/h1>\n<p>\u5e0c\u5c14\u6392\u5e8f\u6cd5(\u7f29\u5c0f\u589e\u91cf\u6cd5) \u5c5e\u4e8e\u63d2\u5165\u7c7b\u6392\u5e8f\uff0c\u662f\u5c06\u6574\u4e2a\u65e0\u5e8f\u5217\u5206\u5272\u6210\u82e5\u5e72\u5c0f\u7684\u5b50\u5e8f\u5217\u5206\u522b\u8fdb\u884c\u63d2\u5165\u6392\u5e8f\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u628a\u8bb0\u5f55\u6309\u4e0b\u6807\u7684\u4e00\u5b9a\u589e\u91cf\u5206\u7ec4\uff0c\u5bf9\u6bcf\u7ec4\u4f7f\u7528\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u7b97\u6cd5\u6392\u5e8f\uff1b\u968f\u7740\u589e\u91cf\u9010\u6e10\u51cf\u5c11\uff0c\u6bcf\u7ec4\u5305\u542b\u7684\u5173\u952e\u8bcd\u8d8a\u6765\u8d8a\u591a\uff0c\u5f53\u589e\u91cf\u51cf\u81f31\u65f6\uff0c\u6574\u4e2a\u6587\u4ef6\u6070\u88ab\u5206\u6210\u4e00\u7ec4\uff0c\u7b97\u6cd5\u4fbf\u7ec8\u6b62\u3002<\/p>\n<p>\u5e0c\u5c14\u6392\u5e8f\u662f\u57fa\u4e8e\u63d2\u5165\u6392\u5e8f\u7684\u4ee5\u4e0b\u4e24\u70b9\u6027\u8d28\u800c\u63d0\u51fa\u6539\u8fdb\u65b9\u6cd5\u7684\uff1a<\/p>\n<ul>\n<li>\u63d2\u5165\u6392\u5e8f\u5728\u5bf9\u51e0\u4e4e\u5df2\u7ecf\u6392\u597d\u5e8f\u7684\u6570\u636e\u64cd\u4f5c\u65f6\uff0c\u6548\u7387\u9ad8\uff0c\u5373\u53ef\u4ee5\u8fbe\u5230\u7ebf\u6027\u6392\u5e8f\u7684\u6548\u7387\u3002<\/li>\n<li>\u4f46\u63d2\u5165\u6392\u5e8f\u4e00\u822c\u6765\u8bf4\u662f\u4f4e\u6548\u7684\uff0c\u56e0\u4e3a\u63d2\u5165\u6392\u5e8f\u6bcf\u6b21\u53ea\u80fd\u5c06\u6570\u636e\u79fb\u52a8\u4e00\u4f4d\u3002<\/li>\n<\/ul>\n<h1 id=\"\u5b9e\u73b0\u8fc7\u7a0b\"><a name=\"t12\"><\/a><a target=\"_blank\" name=\"t12\"><\/a>\u5b9e\u73b0\u8fc7\u7a0b<\/h1>\n<p>\u5148\u53d6\u4e00\u4e2a\u6b63\u6574\u6570d1\u5c0f\u4e8en\uff0c\u628a\u6240\u6709\u5e8f\u53f7\u76f8\u9694d1\u7684\u6570\u7ec4\u5143\u7d20\u653e\u4e00\u7ec4\uff0c\u7ec4\u5185\u8fdb\u884c\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\uff1b\u7136\u540e\u53d6d2\u5c0f\u4e8ed1\uff0c\u91cd\u590d\u4e0a\u8ff0\u5206\u7ec4\u548c\u6392\u5e8f\u64cd\u4f5c\uff1b\u76f4\u81f3di=1\uff0c\u5373\u6240\u6709\u8bb0\u5f55\u653e\u8fdb\u4e00\u4e2a\u7ec4\u4e2d\u6392\u5e8f\u4e3a\u6b62\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u8fd9\u6837\u4e00\u7ec4\u6570[ 13 14 94 33 82 25 59 94 65 23 45 27 73 25 39 10 ]\uff0c\u5982\u679c\u6211\u4eec\u4ee5\u6b65\u957f\u4e3a5\u5f00\u59cb\u8fdb\u884c\u6392\u5e8f\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5c06\u8fd9\u5217\u8868\u653e\u5728\u67095\u5217\u7684\u8868\u4e2d\u6765\u66f4\u597d\u5730\u63cf\u8ff0\u7b97\u6cd5\uff0c\u8fd9\u6837\u4ed6\u4eec\u5c31\u5e94\u8be5\u770b\u8d77\u6765\u662f\u8fd9\u6837\uff1a<\/p>\n<blockquote><p>13 14 94 33 82<br \/>\n25 59 94 65 23<br \/>\n45 27 73 25 39<br \/>\n10<\/p><\/blockquote>\n<p>\u7136\u540e\u6211\u4eec\u5bf9\u6bcf\u5217\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n<blockquote><p>10 14 73 25 23<br \/>\n13 27 94 33 39<br \/>\n25 59 94 65 82<br \/>\n45<\/p><\/blockquote>\n<p>\u5c06\u4e0a\u8ff0\u56db\u884c\u6570\u5b57\uff0c\u4f9d\u5e8f\u63a5\u5728\u4e00\u8d77\u65f6\u6211\u4eec\u5f97\u5230\uff1a[ 10 14 73 25 23 13 27 94 33 39 25 59 94 65 82 45 ].\u8fd9\u65f610\u5df2\u7ecf\u79fb\u81f3\u6b63\u786e\u4f4d\u7f6e\u4e86\uff0c\u7136\u540e\u518d\u4ee53\u4e3a\u6b65\u957f\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n<blockquote><p>10 14 73<br \/>\n25 23 13<br \/>\n27 94 33<br \/>\n39 25 59<br \/>\n94 65 82<br \/>\n45<\/p><\/blockquote>\n<p>\u6392\u5e8f\u4e4b\u540e\u53d8\u4e3a\uff1a<\/p>\n<blockquote><p>10 14 13<br \/>\n25 23 33<br \/>\n27 25 59<br \/>\n39 65 73<br \/>\n45 94 82<br \/>\n94<\/p><\/blockquote>\n<p>\u6700\u540e\u4ee51\u6b65\u957f\u8fdb\u884c\u6392\u5e8f\uff08\u6b64\u65f6\u5c31\u662f\u7b80\u5355\u7684\u63d2\u5165\u6392\u5e8f\u4e86\uff09\u3002<\/p>\n<h1 id=\"\u5b9e\u73b0\u6548\u7387\"><a name=\"t13\"><\/a><a target=\"_blank\" name=\"t13\"><\/a>\u5b9e\u73b0\u6548\u7387<\/h1>\n<p>\u5e0c\u5c14\u6392\u5e8f\u662f\u4e00\u4e2a\u4e0d\u7a33\u5b9a\u7684\u6392\u5e8f\uff0c\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u53d7\u6b65\u957f\uff08\u589e\u91cf\uff09\u7684\u5f71\u54cd\u3002<\/p>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6\uff1a\u3000\uff2f(1)<\/p>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u3000\u5e73\u5747 O(n^1.3)<br \/>\n\u6700\u597d\u3000O(n)<br \/>\n\u6700\u574f\u3000O(n^2)<\/p>\n<h1 id=\"java\u5b9e\u73b0-1\"><a name=\"t14\"><\/a><a target=\"_blank\" name=\"t14\"><\/a>Java\u5b9e\u73b0<\/h1>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cs has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;shellSort&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] a) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; gap = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;, i, j, len = a.length; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; temp;&lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u63d2\u5165\u6392\u5e8f\u4ea4\u6362\u503c\u7684\u6682\u5b58&lt;\/span&gt; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u786e\u5b9a\u521d\u59cb\u6b65\u957f&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt; (gap &lt; len \/ &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;3&lt;\/span&gt;){ gap = gap * &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;3&lt;\/span&gt; + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt; (; gap &gt; &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; gap \/= &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;3&lt;\/span&gt;){&lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5faa\u73af\u904d\u5386\u6b65\u957f\uff0c\u6700\u540e\u5fc5\u4e3a1&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt; (i = gap; i &lt; len; i++) {&lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u6bcf\u4e00\u5217\u4f9d\u6b21\u5411\u524d\u505a\u63d2\u5165\u6392\u5e8f&lt;\/span&gt; temp = a[i]; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u6bcf\u4e00\u5217\u4e2d\u5728a[i]\u4e0a\u9762\u4e14\u6bd4a[i]\u5927\u7684\u5143\u7d20\u4f9d\u6b21\u5411\u4e0b\u79fb\u52a8&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt; (j = i - gap; j &gt;= &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt; &amp;&amp; a[j] &gt; temp; j -= gap){ a[j + gap] = a[j]; } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/a[i]\u586b\u8865\u7a7a\u767d\uff0c\u5b8c\u6210\u4e00\u5217\u4e2d\u7684\u4f9d\u6b21\u63d2\u5165\u6392\u5e8f&lt;\/span&gt; a[j + gap] = temp; } } }&lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u4e94\u3001\u5f52\u5e76\u6392\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"title-3\"><a target=\"_blank\" name=\"t15\"><\/a><\/h2>\n<h1 id=\"\uff11\u6982\u8ff0\"><a name=\"t16\"><\/a><a target=\"_blank\" name=\"t16\"><\/a>\uff11.\u6982\u8ff0<\/h1>\n<p>\u5f52\u5e76\u6392\u5e8f\uff0c\u662f\u521b\u5efa\u5728\u5f52\u5e76\u64cd\u4f5c\u4e0a\u7684\u4e00\u79cd\u6709\u6548\u7684\u6392\u5e8f\u7b97\u6cd5\u8be5\u7b97\u6cd5\u662f\u91c7\u7528\u5206\u6cbb\u6cd5\uff08Divide and Conquer\uff09\u7684\u4e00\u4e2a\u975e\u5e38\u5178\u578b\u7684\u5e94\u7528\uff0c\u4e14\u5404\u5c42\u5206\u6cbb\u9012\u5f52\u53ef\u4ee5\u540c\u65f6\u8fdb\u884c\u3002<\/p>\n<p>\u5373\u5148\u4f7f\u6bcf\u4e2a\u5b50\u5e8f\u5217\u6709\u5e8f\uff0c\u518d\u5c06\u4e24\u4e2a\u5df2\u7ecf\u6392\u5e8f\u7684\u5e8f\u5217\u5408\u5e76\u6210\u4e00\u4e2a\u5e8f\u5217\u7684\u64cd\u4f5c\u3002\u82e5\u5c06\u4e24\u4e2a\u6709\u5e8f\u8868\u5408\u5e76\u6210\u4e00\u4e2a\u6709\u5e8f\u8868\uff0c\u79f0\u4e3a\u4e8c\u8def\u5f52\u5e76\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<blockquote><p>\u8bbe\u6709\u6570\u5217{6\uff0c202\uff0c100\uff0c301\uff0c38\uff0c8\uff0c1}<br \/>\n\u521d\u59cb\u72b6\u6001\uff1a6,202,100,301,38,8\uff0c1<br \/>\n\u7b2c\u4e00\u6b21\u5f52\u5e76\u540e\uff1a{6,202},{100,301},{8,38},{1}\uff0c\u6bd4\u8f83\u6b21\u6570\uff1a3\uff1b<br \/>\n\u7b2c\u4e8c\u6b21\u5f52\u5e76\u540e\uff1a{6,100,202,301}\uff0c{1,8,38}\uff0c\u6bd4\u8f83\u6b21\u6570\uff1a4\uff1b<br \/>\n\u7b2c\u4e09\u6b21\u5f52\u5e76\u540e\uff1a{1,6,8,38,100,202,301},\u6bd4\u8f83\u6b21\u6570\uff1a4\uff1b<br \/>\n\u603b\u7684\u6bd4\u8f83\u6b21\u6570\u4e3a\uff1a3+4+4=11,\uff1b<br \/>\n\u9006\u5e8f\u6570\u4e3a14\uff1b<\/p><\/blockquote>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160517150920429\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5f52\u5e76\u6392\u5e8f\u793a\u610f\u56fe<\/p>\n<h1 id=\"\uff12\u6548\u7387\"><a name=\"t17\"><\/a><a target=\"_blank\" name=\"t17\"><\/a>\uff12.\u6548\u7387<\/h1>\n<p>\u5f52\u5e76\u6392\u5e8f\u901f\u5ea6\u4ec5\u6b21\u4e8e\u5feb\u901f\u6392\u5e8f\uff0c\u4e3a\u7a33\u5b9a\u6392\u5e8f\u7b97\u6cd5\uff08\u5373\u76f8\u7b49\u7684\u5143\u7d20\u7684\u987a\u5e8f\u4e0d\u4f1a\u6539\u53d8\uff09\uff0c\u4e00\u822c\u7528\u4e8e\u5bf9\u603b\u4f53\u65e0\u5e8f\uff0c\u4f46\u662f\u5404\u5b50\u9879\u76f8\u5bf9\u6709\u5e8f\u7684\u6570\u5217.<\/p>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(nlogn)<\/p>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a\u00a0O(n)<\/p>\n<p>\u5f52\u5e76\u6392\u5e8f\u6bd4\u8f83\u5360\u7528\u5185\u5b58\uff0c\u4f46\u5374\u662f\u4e00\u79cd\u6548\u7387\u9ad8\u4e14\u7a33\u5b9a\u7684\u7b97\u6cd5\u3002<\/p>\n<h1 id=\"3\u8fed\u4ee3\u5b9e\u73b0\"><a name=\"t18\"><\/a><a target=\"_blank\" name=\"t18\"><\/a>3.\u8fed\u4ee3\u5b9e\u73b0<\/h1>\n<h2 id=\"3\uff11\u5b9e\u73b0\u539f\u7406\"><a name=\"t19\"><\/a><a target=\"_blank\" name=\"t19\"><\/a>3.\uff11\u5b9e\u73b0\u539f\u7406<\/h2>\n<p>\u2460\u7533\u8bf7\u7a7a\u95f4\uff0c\u4f7f\u5176\u5927\u5c0f\u4e3a\u4e24\u4e2a\u5df2\u7ecf\u6392\u5e8f\u5e8f\u5217\u4e4b\u548c\uff0c\u8be5\u7a7a\u95f4\u7528\u6765\u5b58\u653e\u5408\u5e76\u540e\u7684\u5e8f\u5217<\/p>\n<p>\u2461\u8bbe\u5b9a\u4e24\u4e2a\u6307\u9488\uff0c\u6700\u521d\u4f4d\u7f6e\u5206\u522b\u4e3a\u4e24\u4e2a\u5df2\u7ecf\u6392\u5e8f\u5e8f\u5217\u7684\u8d77\u59cb\u4f4d\u7f6e<\/p>\n<p>\u2462\u6bd4\u8f83\u4e24\u4e2a\u6307\u9488\u6240\u6307\u5411\u7684\u5143\u7d20\uff0c\u9009\u62e9\u76f8\u5bf9\u5c0f\u7684\u5143\u7d20\u653e\u5165\u5230\u5408\u5e76\u7a7a\u95f4\uff0c\u5e76\u79fb\u52a8\u6307\u9488\u5230\u4e0b\u4e00\u4f4d\u7f6e<\/p>\n<p>\u2463\u91cd\u590d\u6b65\u9aa4\u2462\u76f4\u5230\u67d0\u4e00\u6307\u9488\u5230\u8fbe\u5e8f\u5217\u5c3e<\/p>\n<p>\u2464\u5c06\u53e6\u4e00\u5e8f\u5217\u5269\u4e0b\u7684\u6240\u6709\u5143\u7d20\u76f4\u63a5\u590d\u5236\u5230\u5408\u5e76\u5e8f\u5217\u5c3e<\/p>\n<h2 id=\"3\uff12java\u4ee3\u7801\"><a name=\"t20\"><\/a><a target=\"_blank\" name=\"t20\"><\/a>3.\uff12Java\u4ee3\u7801<\/h2>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cs has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;main&lt;\/span&gt;(String[] args) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; [] arr ={&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;6&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;5&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;3&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;8&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;7&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;4&lt;\/span&gt;}; merge_sort(arr); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i : arr){ System.&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;out&lt;\/span&gt;.println(i); } } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;merge_sort&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] arr) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; len = arr.length; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u7528\u4e8e\u5408\u5e76\u7684\u4e34\u65f6\u6570\u7ec4&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] result = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;new&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[len]; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; block, start; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u4e24\u4e24\u5408\u5e76\u540e\u5757\u5927\u5c0f\u53d8\u5927\u4e24\u500d (\u6ce8\u610f\u6700\u540e\u4e00\u6b21block\u7b49\u4e8elen)&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(block = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; block &lt;=len ; block *= &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt;) { &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u628a\u6574\u4e2a\u6570\u7ec4\u5206\u6210\u5f88\u591a\u4e2a\u5757\uff0c\u6bcf\u6b21\u5408\u5e76\u5904\u7406\u4e24\u4e2a\u5757&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(start = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; start &lt;len; start += &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt; * block) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; low = start; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; mid = (start + block) &lt; len ? (start + block) : len; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; high = (start + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt; * block) &lt; len ? (start + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt; * block) : len; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u4e24\u4e2a\u5757\u7684\u8d77\u59cb\u4e0b\u6807\u53ca\u7ed3\u675f\u4e0b\u6807&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; start1 = low, end1 = mid; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; start2 = mid, end2 = high; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5f00\u59cb\u5bf9\u4e24\u4e2ablock\u8fdb\u884c\u5f52\u5e76\u6392\u5e8f&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt; (start1 &lt; end1 &amp;&amp; start2 &lt; end2) { result[low++] = arr[start1] &lt; arr[start2] ? arr[start1++] : arr[start2++]; } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(start1 &lt; end1) { result[low++] = arr[start1++]; } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(start2 &lt; end2) { result[low++] = arr[start2++]; } } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u6bcf\u6b21\u5f52\u5e76\u540e\u628a\u7ed3\u679cresult\u5b58\u5165arr\u4e2d\uff0c\u4ee5\u4fbf\u8fdb\u884c\u4e0b\u6b21\u5f52\u5e76&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] temp = arr; arr = result; result = temp; } }&lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;23&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;24&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;25&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;26&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;27&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;28&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;29&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;30&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;31&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;32&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;33&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;34&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;35&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;36&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;37&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;38&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;39&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;40&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<h1 id=\"4\u9012\u5f52\u5b9e\u73b0\"><a name=\"t21\"><\/a><a target=\"_blank\" name=\"t21\"><\/a>4.\u9012\u5f52\u5b9e\u73b0<\/h1>\n<h2 id=\"4\uff11\u5b9e\u73b0\u539f\u7406\"><a name=\"t22\"><\/a><a target=\"_blank\" name=\"t22\"><\/a>4.\uff11\u5b9e\u73b0\u539f\u7406<\/h2>\n<p>\u5047\u8bbe\u5e8f\u5217\u5171\u6709n\u4e2a\u5143\u7d20<\/p>\n<p>\u2460\u5c06\u5e8f\u5217\u6bcf\u76f8\u90bb\u4e24\u4e2a\u6570\u5b57\u8fdb\u884c\u5f52\u5e76\u64cd\u4f5c\uff0c\u5f62\u6210floor(n\/2)\u4e2a\u5e8f\u5217\uff0c\u6392\u5e8f\u540e\u6bcf\u4e2a\u5e8f\u5217\u5305\u542b\u4e24\u4e2a\u5143\u7d20\u3002<\/p>\n<p>\u2461\u5c06\u4e0a\u8ff0\u5e8f\u5217\u518d\u6b21\u5f52\u5e76\uff0c\u5f62\u6210floor(n\/4)\u4e2a\u5e8f\u5217\uff0c\u6bcf\u4e2a\u5e8f\u5217\u5305\u542b\u56db\u4e2a\u5143\u7d20<\/p>\n<p>\u2462\u91cd\u590d\u6b65\u9aa4\u2461\uff0c\u76f4\u5230\u6240\u6709\u5143\u7d20\u6392\u5e8f\u5b8c\u6bd5<\/p>\n<h2 id=\"4\uff12java\u4ee3\u7801\"><a name=\"t23\"><\/a><a target=\"_blank\" name=\"t23\"><\/a>4.\uff12Java\u4ee3\u7801<\/h2>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cs has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;main&lt;\/span&gt;(String[] args) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; [] arr ={&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;6&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;5&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;3&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;8&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;7&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;4&lt;\/span&gt;}; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; len = arr.length; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] reg = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;new&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[len]; merge_sort_recursive(arr,reg,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;,len-&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i : arr){ System.&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;out&lt;\/span&gt;.println(i); } } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; merge_sort_recursive(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] arr, &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] reg, &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; start, &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; end) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt; (start &gt;= end) &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;return&lt;\/span&gt;; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; len = end - start, mid = (len &gt;&gt; &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;) + start; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; start1 = start, end1 = mid; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; start2 = mid + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;, end2 = end; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u9012\u5f52\u5230\u5b50\u5e8f\u5217\u53ea\u6709\u4e00\u4e2a\u6570\u7684\u65f6\u5019\uff0c\u5f00\u59cb\u9010\u4e2a\u8fd4\u56de&lt;\/span&gt; merge_sort_recursive(arr, reg, start1, end1); merge_sort_recursive(arr, reg, start2, end2); &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/-------\u5408\u5e76\u64cd\u4f5c\uff0c\u5fc5\u987b\u5728\u9012\u5f52\u4e4b\u540e\uff08\u5b50\u5e8f\u5217\u6709\u5e8f\u7684\u57fa\u7840\u4e0a\uff09----&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; k = start; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt; (start1 &lt;= end1 &amp;&amp; start2 &lt;= end2) reg[k++] = arr[start1] &lt; arr[start2] ? arr[start1++] : arr[start2++]; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt; (start1 &lt;= end1) reg[k++] = arr[start1++]; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt; (start2 &lt;= end2) reg[k++] = arr[start2++]; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u501f\u7528reg\u6570\u7ec4\u505a\u5408\u5e76\uff0c\u7136\u540e\u628a\u6570\u636e\u5b58\u56dearr\u4e2d&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt; (k = start; k &lt;= end; k++) arr[k] = reg[k]; }&lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;23&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;24&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;25&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;26&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;27&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;28&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;29&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;30&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u516d\u3001\u5feb\u901f\u6392\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"title-4\"><a target=\"_blank\" name=\"t24\"><\/a><\/h2>\n<h1 id=\"\u57fa\u672c\u601d\u60f3\"><a name=\"t25\"><\/a><a target=\"_blank\" name=\"t25\"><\/a>\u57fa\u672c\u601d\u60f3<\/h1>\n<p>\u5feb\u901f\u6392\u5e8f\uff08Quicksort\uff09\u662f\u5bf9\u5192\u6ce1\u6392\u5e8f\u7684\u4e00\u79cd\u6539\u8fdb\uff0c\u53c8\u79f0\u5212\u5206\u4ea4\u6362\u6392\u5e8f\uff08partition-exchange sort\u3002<\/p>\n<p>\u5feb\u901f\u6392\u5e8f\u4f7f\u7528\u5206\u6cbb\u6cd5\uff08Divide and conquer\uff09\u7b56\u7565\u6765\u628a\u4e00\u4e2a\u5e8f\u5217\uff08list\uff09\u5206\u4e3a\u4e24\u4e2a\u5b50\u5e8f\u5217\uff08sub-lists\uff09\u3002<\/p>\n<p>\u6b65\u9aa4\u4e3a\uff1a<\/p>\n<p>\u2460\uff0e\u4ece\u6570\u5217\u4e2d\u6311\u51fa\u4e00\u4e2a\u5143\u7d20\uff0c\u79f0\u4e3a\u201d\u57fa\u51c6\u201d\uff08pivot\uff09<\/p>\n<p>\u2461\uff0e\u91cd\u65b0\u6392\u5e8f\u6570\u5217\uff0c\u6240\u6709\u5143\u7d20\u6bd4\u57fa\u51c6\u503c\u5c0f\u7684\u6446\u653e\u5728\u57fa\u51c6\u524d\u9762\uff0c\u6240\u6709\u5143\u7d20\u6bd4\u57fa\u51c6\u503c\u5927\u7684\u6446\u5728\u57fa\u51c6\u7684\u540e\u9762\uff08\u76f8\u540c\u7684\u6570\u53ef\u4ee5\u5230\u4efb\u4e00\u8fb9\uff09\u3002\u5728\u8fd9\u4e2a\u5206\u533a\u7ed3\u675f\u4e4b\u540e\uff0c\u8be5\u57fa\u51c6\u5c31\u5904\u4e8e\u6570\u5217\u7684\u4e2d\u95f4\u4f4d\u7f6e\u3002\u8fd9\u4e2a\u79f0\u4e3a\u5206\u533a\uff08partition\uff09\u64cd\u4f5c\u3002<\/p>\n<p>\u2462\uff0e\u9012\u5f52\u5730\uff08recursive\uff09\u628a\u5c0f\u4e8e\u57fa\u51c6\u503c\u5143\u7d20\u7684\u5b50\u6570\u5217\u548c\u5927\u4e8e\u57fa\u51c6\u503c\u5143\u7d20\u7684\u5b50\u6570\u5217\u6392\u5e8f<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160519164311224\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4f7f\u7528\u5feb\u901f\u6392\u5e8f\u6cd5\u5bf9\u4e00\u5217\u6570\u5b57\u8fdb\u884c\u6392\u5e8f\u7684\u8fc7\u7a0b<\/p>\n<h1 id=\"\u6392\u5e8f\u6548\u7387\"><a name=\"t26\"><\/a><a target=\"_blank\" name=\"t26\"><\/a>\u6392\u5e8f\u6548\u7387<\/h1>\n<p>\u5728\u5e73\u5747\u72b6\u51b5\u4e0b\uff0c\u6392\u5e8fn\u4e2a\u9879\u76ee\u8981\u039f(n log n)\u6b21\u6bd4\u8f83\u3002\u5728\u6700\u574f\u72b6\u51b5\u4e0b\u5219\u9700\u8981\u039f(n2)\u6b21\u6bd4\u8f83\uff0c\u4f46\u8fd9\u79cd\u72b6\u51b5\u5e76\u4e0d\u5e38\u89c1\u3002\u4e8b\u5b9e\u4e0a\uff0c\u5feb\u901f\u6392\u5e8f\u901a\u5e38\u660e\u663e\u6bd4\u5176\u4ed6\u039f(n log n)\u7b97\u6cd5\u66f4\u5feb\uff0c\u56e0\u4e3a\u5b83\u7684\u5185\u90e8\u5faa\u73af\uff08inner loop\uff09\u53ef\u4ee5\u5728\u5927\u90e8\u5206\u7684\u67b6\u6784\u4e0a\u5f88\u6709\u6548\u7387\u5730\u88ab\u5b9e\u73b0\u51fa\u6765\u3002<\/p>\n<p>\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 \u039f(n^2)<\/p>\n<p>\u6700\u4f18\u65f6\u95f4\u590d\u6742\u5ea6 \u039f(n log n)<\/p>\n<p>\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u039f(n log n)<\/p>\n<p>\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6 \u6839\u636e\u5b9e\u73b0\u7684\u65b9\u5f0f\u4e0d\u540c\u800c\u4e0d\u540c<\/p>\n<h1 id=\"java\u5b9e\u73b0-2\"><a name=\"t27\"><\/a><a target=\"_blank\" name=\"t27\"><\/a>Java\u5b9e\u73b0<\/h1>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cpp has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; main(String[] args) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; [] arr = {&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;8&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;4&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;6&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;7&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;9&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;5&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;3&lt;\/span&gt;}; quickSort(arr,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;,arr.length-&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i :arr){ System.out.println(i); } } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; quickSort(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[]arr,&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; low,&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; high){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt; (low &lt; high) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; middle = getMiddle(arr, low, high); quickSort(arr, low, middle - &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;); quickSort(arr, middle + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;, high); } } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; getMiddle(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;, &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; low, &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; high) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; tmp = &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;[low]; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt; (low &lt; high) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt; (low &lt; high &amp;&amp; &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;[high] &gt;= tmp) { high--; } &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;[low] = &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;[high]; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt; (low &lt; high &amp;&amp; &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;[low] &lt;= tmp) { low++; } &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;[high] = &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;[low]; } &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;[low] = tmp; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;return&lt;\/span&gt; low; } &lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;23&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;24&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;25&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;26&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;27&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;28&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;29&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160519181157295\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5206\u6790\uff1a<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160519180035248\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<blockquote><p>\u53d6\uff18\u4e3a\u4e2d\u503c\uff0c\u7ea2\u8272\u7bad\u5934\u8868\u793alow\uff0c\u7eff\u8272\u7bad\u5934\u8868\u793ahigh<\/p><\/blockquote>\n<p>\u2460\u4ecehigh\u5f00\u59cb\u5411\u524d\u626b\u63cf\u5230\u7b2c\u4e00\u4e2a\u6bd4\uff18\u5c0f\u7684\u503c\u4e0e\uff18\u4ea4\u6362\u3002<\/p>\n<p>\u2461\u4ecelow\u5411\u540e\u626b\u63cf\u7b2c\u4e00\u6bd48\u5927\u7684\u503c\u4e0e8\u4ea4\u6362\u3002<\/p>\n<p>\u2462\u91cd\u590d\u2460\u2461\u8fc7\u7a0b\u53ea\u5230\uff0chigh=low\u5b8c\u6210\u4e00\u6b21\u5feb\u901f\u6392\u5e8f\uff0c\u7136\u540e\u9012\u5f52\u5b50\u5e8f\u5217\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u4e03\u3001\u5806\u6392\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"title-5\"><a target=\"_blank\" name=\"t28\"><\/a><\/h2>\n<h1 id=\"\u6d45\u6790\u5806\"><a name=\"t29\"><\/a><a target=\"_blank\" name=\"t29\"><\/a>\u6d45\u6790\u5806<\/h1>\n<p>\u5806\u6392\u5e8f(Heapsort)\u662f\u6307\u5229\u7528\u5806\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u6240\u8bbe\u8ba1\u7684\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\uff0c\u5b83\u662f\u9009\u62e9\u6392\u5e8f\u7684\u4e00\u79cd\u3002\u53ef\u4ee5\u5229\u7528\u6570\u7ec4\u7684\u7279\u70b9\u5feb\u901f\u5b9a\u4f4d\u6307\u5b9a\u7d22\u5f15\u7684\u5143\u7d20\u3002\u5806\u5206\u4e3a\u5927\u6839\u5806\u548c\u5c0f\u6839\u5806\uff0c\u662f\u5b8c\u5168\u4e8c\u53c9\u6811\u3002\u5927\u6839\u5806\u7684\u8981\u6c42\u662f\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u4e0d\u5927\u4e8e\u5176\u7236\u8282\u70b9\u7684\u503c\u3002<\/p>\n<p>\u7531\u4e8e\u5806\u4e2d\u6bcf\u6b21\u90fd\u53ea\u80fd\u5220\u9664\u7b2c0\u4e2a\u6570\u636e\uff0c\u901a\u8fc7\u3000\u53d6\u51fa\u7b2c\uff10\u4e2a\u6570\u636e\u518d\u6267\u884c\u5806\u7684\u5220\u9664\u64cd\u4f5c\u3001\u91cd\u5efa\u5806\uff08\u5b9e\u9645\u7684\u64cd\u4f5c\u662f\u5c06\u6700\u540e\u4e00\u4e2a\u6570\u636e\u7684\u503c\u8d4b\u7ed9\u6839\u7ed3\u70b9\uff0c\u7136\u540e\u518d\u4ece\u6839\u7ed3\u70b9\u5f00\u59cb\u8fdb\u884c\u4e00\u6b21\u4ece\u4e0a\u5411\u4e0b\u7684\u8c03\u6574\u3002\uff09\uff0c\u7136\u540e\u518d\u53d6\uff0c\u5982\u6b64\u91cd\u590d\u5b9e\u73b0\u6392\u5e8f\u3002<\/p>\n<p>\u5806\u7684\u64cd\u4f5c\uff1a<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160523164108748\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5728\u5806\u7684\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u5806\u4e2d\u7684\u6700\u5927\u503c\u603b\u662f\u4f4d\u4e8e\u6839\u8282\u70b9\u3002\u5806\u4e2d\u5b9a\u4e49\u4ee5\u4e0b\u51e0\u79cd\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li>\u6700\u5927\u5806\u8c03\u6574\uff08Max_Heapify\uff09\uff1a\u5c06\u5806\u7684\u672b\u7aef\u5b50\u8282\u70b9\u4f5c\u8c03\u6574\uff0c\u4f7f\u5f97\u5b50\u8282\u70b9\u6c38\u8fdc\u5c0f\u4e8e\u7236\u8282\u70b9<\/li>\n<li>\u521b\u5efa\u6700\u5927\u5806\uff08Build_Max_Heap\uff09\uff1a\u5c06\u5806\u6240\u6709\u6570\u636e\u91cd\u65b0\u6392\u5e8f<\/li>\n<li>\u5806\u6392\u5e8f\uff08HeapSort\uff09\uff1a\u79fb\u9664\u4f4d\u5728\u7b2c\u4e00\u4e2a\u6570\u636e\u7684\u6839\u8282\u70b9\uff0c\u5e76\u505a\u6700\u5927\u5806\u8c03\u6574\u7684\u9012\u5f52\u8fd0\u7b97<\/li>\n<\/ul>\n<p>\u5806\u7684\u5b58\u50a8\uff1a<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"http:\/\/hi.csdn.net\/attachment\/201108\/22\/0_1314014706gZqn.gif\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u901a\u5e38\u5806\u662f\u901a\u8fc7\u4e00\u7ef4\u6570\u7ec4\u6765\u5b9e\u73b0\u7684\u3002\u5728\u6570\u7ec4\u8d77\u59cb\u4f4d\u7f6e\u4e3a0\u7684\u60c5\u5f62\u4e2d\uff1a<\/p>\n<ul>\n<li>\u7236\u8282\u70b9i\u7684\u5de6\u5b50\u8282\u70b9\u5728\u4f4d\u7f6e(2*i+1);<\/li>\n<li>\u7236\u8282\u70b9i\u7684\u53f3\u5b50\u8282\u70b9\u5728\u4f4d\u7f6e(2*i+2);<\/li>\n<li>\u5b50\u8282\u70b9i\u7684\u7236\u8282\u70b9\u5728\u4f4d\u7f6efloor((i-1)\/2);<\/li>\n<\/ul>\n<h1 id=\"java\u4ee3\u7801\u5b9e\u73b0\"><a name=\"t30\"><\/a><a target=\"_blank\" name=\"t30\"><\/a>Java\u4ee3\u7801\u5b9e\u73b0<\/h1>\n<pre class=\"prettyprint\">&lt;code class=\"hljs java has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-class\" style=\"box-sizing: border-box;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;class&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box; color: rgb(102, 0, 102);\"&gt;HeapSort&lt;\/span&gt; {&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;private&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] sort = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;new&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[]{&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;10&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;20&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;3&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;5&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;6&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;4&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;9&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;8&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;12&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;17&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;34&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;11&lt;\/span&gt;}; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;main&lt;\/span&gt;(String[] args) { buildMaxHeapify(sort); heapSort(sort); print(sort); } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;private&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;buildMaxHeapify&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] data){ &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u624d\u9700\u8981\u521b\u5efa\u6700\u5927\u5806\uff0c\u4ece\u6700\u540e\u4e00\u4e2a\u7684\u7236\u8282\u70b9\u5f00\u59cb&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; startIndex = getParentIndex(data.length - &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;); &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u4ece\u5c3e\u7aef\u5f00\u59cb\u521b\u5efa\u6700\u5927\u5806\uff0c\u6bcf\u6b21\u90fd\u662f\u6b63\u786e\u7684\u5806&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt; (&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i = startIndex; i &gt;= &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; i--) { maxHeapify(data, data.length, i); } } &lt;span class=\"hljs-javadoc\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/** * \u521b\u5efa\u6700\u5927\u5806 *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @param&lt;\/span&gt; data *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @param&lt;\/span&gt; heapSize\u9700\u8981\u521b\u5efa\u6700\u5927\u5806\u7684\u5927\u5c0f\uff0c\u4e00\u822c\u5728sort\u7684\u65f6\u5019\u7528\u5230\uff0c\u56e0\u4e3a\u6700\u591a\u503c\u653e\u5728\u672b\u5c3e\uff0c\u672b\u5c3e\u5c31\u4e0d\u518d\u5f52\u5165\u6700\u5927\u5806\u4e86 *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @param&lt;\/span&gt; index\u5f53\u524d\u9700\u8981\u521b\u5efa\u6700\u5927\u5806\u7684\u4f4d\u7f6e *\/&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;private&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;maxHeapify&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] data, &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; heapSize, &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; index){ &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/ \u5f53\u524d\u70b9\u4e0e\u5de6\u53f3\u5b50\u8282\u70b9\u6bd4\u8f83&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; left = getChildLeftIndex(index); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; right = getChildRightIndex(index); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; largest = index; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt; (left &lt; heapSize &amp;&amp; data[index] &lt; data[left]) { largest = left; } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt; (right &lt; heapSize &amp;&amp; data[largest] &lt; data[right]) { largest = right; } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5f97\u5230\u6700\u5927\u503c\u540e\u53ef\u80fd\u9700\u8981\u4ea4\u6362\uff0c\u5982\u679c\u4ea4\u6362\u4e86\uff0c\u5176\u5b50\u8282\u70b9\u53ef\u80fd\u5c31\u4e0d\u662f\u6700\u5927\u5806\u4e86\uff0c\u9700\u8981\u91cd\u65b0\u8c03\u6574&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt; (largest != index) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; temp = data[index]; data[index] = data[largest]; data[largest] = temp; maxHeapify(data, heapSize, largest); } } &lt;span class=\"hljs-javadoc\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/** * \u6392\u5e8f\uff0c\u6700\u5927\u503c\u653e\u5728\u672b\u5c3e\uff0cdata\u867d\u7136\u662f\u6700\u5927\u5806\uff0c\u5728\u6392\u5e8f\u540e\u5c31\u6210\u4e86\u9012\u589e\u7684 *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @param&lt;\/span&gt; data *\/&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;private&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;heapSort&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] data) { &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u672b\u5c3e\u4e0e\u5934\u4ea4\u6362\uff0c\u4ea4\u6362\u540e\u8c03\u6574\u6700\u5927\u5806&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt; (&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i = data.length - &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; i &gt; &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; i--) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; temp = data[&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;]; data[&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;] = data[i]; data[i] = temp; maxHeapify(data, i, &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;); } } &lt;span class=\"hljs-javadoc\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/** * \u7236\u8282\u70b9\u4f4d\u7f6e *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @param&lt;\/span&gt; current *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @return&lt;\/span&gt; *\/&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;private&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;getParentIndex&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; current){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;return&lt;\/span&gt; (current - &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;) &gt;&gt; &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; } &lt;span class=\"hljs-javadoc\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/** * \u5de6\u5b50\u8282\u70b9position\u6ce8\u610f\u62ec\u53f7\uff0c\u52a0\u6cd5\u4f18\u5148\u7ea7\u66f4\u9ad8 *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @param&lt;\/span&gt; current *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @return&lt;\/span&gt; *\/&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;private&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;getChildLeftIndex&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; current){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;return&lt;\/span&gt; (current &lt;&lt; &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;) + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; } &lt;span class=\"hljs-javadoc\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/** * \u53f3\u5b50\u8282\u70b9position *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @param&lt;\/span&gt; current *&lt;span class=\"hljs-javadoctag\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt; @return&lt;\/span&gt; *\/&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;private&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;getChildRightIndex&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; current){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;return&lt;\/span&gt; (current &lt;&lt; &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;) + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt;; } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;private&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;print&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] data){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt; (&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; i &lt; data.length; i++) { System.out.print(data[i] + &lt;span class=\"hljs-string\" style=\"color: rgb(0, 136, 0); box-sizing: border-box;\"&gt;\" |\"&lt;\/span&gt;); } } } &lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;23&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;24&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;25&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;26&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;27&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;28&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;29&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;30&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;31&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;32&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;33&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;34&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;35&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;36&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;37&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;38&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;39&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;40&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;41&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;42&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;43&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;44&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;45&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;46&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;47&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;48&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;49&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;50&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;51&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;52&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;53&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;54&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;55&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;56&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;57&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;58&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;59&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;60&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;61&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;62&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;63&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;64&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;65&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;66&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;67&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;68&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;69&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;70&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;71&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;72&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;73&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;74&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;75&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;76&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;77&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;78&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;79&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;80&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;81&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;82&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;83&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;84&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;85&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;86&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;87&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;88&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;89&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;90&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;91&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;92&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;93&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u516b\u3001\u6876\u6392\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"title-6\"><a target=\"_blank\" name=\"t31\"><\/a><\/h2>\n<h1 id=\"1\u6982\u5ff5\"><a name=\"t32\"><\/a><a target=\"_blank\" name=\"t32\"><\/a>1.\u6982\u5ff5<\/h1>\n<p>\u6876\u6392\u5e8f\uff08Bucket sort\uff09\u6216\u6240\u8c13\u7684\u7bb1\u6392\u5e8f\uff0c\u662f\u4e00\u4e2a\u6392\u5e8f\u7b97\u6cd5\u3002<\/p>\n<p>\u5047\u8bbe\u6709\u4e00\u7ec4\u957f\u5ea6\u4e3aN\u7684\u5f85\u6392\u5173\u952e\u5b57\u5e8f\u5217K[1\u2026.n]\u3002\u9996\u5148\u5c06\u8fd9\u4e2a\u5e8f\u5217\u5212\u5206\u6210M\u4e2a\u7684\u5b50\u533a\u95f4(\u6876) \u3002\u7136\u540e\u57fa\u4e8e\u67d0\u79cd\u6620\u5c04\u51fd\u6570 \uff0c\u5c06\u5f85\u6392\u5e8f\u5217\u7684\u5173\u952e\u5b57k\u6620\u5c04\u5230\u7b2ci\u4e2a\u6876\u4e2d(\u5373\u6876\u6570\u7ec4B\u7684\u4e0b\u6807 i) \uff0c\u90a3\u4e48\u8be5\u5173\u952e\u5b57k\u5c31\u4f5c\u4e3aB[i]\u4e2d\u7684\u5143\u7d20\u3002\u63a5\u7740\u5bf9\u6bcf\u4e2a\u6876B[i]\u4e2d\u7684\u6240\u6709\u5143\u7d20\u8fdb\u884c\u6bd4\u8f83\u6392\u5e8f(\u53ef\u4ee5\u4f7f\u7528\u5feb\u6392)\u3002\u7136\u540e\u4f9d\u6b21\u679a\u4e3e\u8f93\u51faB[0]\u2026.B[M]\u4e2d\u7684\u5168\u90e8\u5185\u5bb9\u5373\u662f\u4e00\u4e2a\u6709\u5e8f\u5e8f\u5217\u3002<\/p>\n<p>\u6876\u6392\u5e8f\u7684\u6b65\u9aa4\uff1a<\/p>\n<p>\u2460\u8bbe\u7f6e\u4e00\u4e2a\u5b9a\u91cf\u7684\u6570\u7ec4\u5f53\u4f5c\u7a7a\u6876\u5b50\u3002<\/p>\n<p>\u2461\u5bfb\u8bbf\u5e8f\u5217\uff0c\u5e76\u4e14\u628a\u9879\u76ee\u4e00\u4e2a\u4e00\u4e2a\u653e\u5230\u5bf9\u5e94\u7684\u6876\u5b50\u53bb\u3002<\/p>\n<p>\u2462\u5bf9\u6bcf\u4e2a\u4e0d\u662f\u7a7a\u7684\u6876\u5b50\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p>\u2463\u4ece\u4e0d\u662f\u7a7a\u7684\u6876\u5b50\u91cc\u628a\u9879\u76ee\u518d\u653e\u56de\u539f\u6765\u7684\u5e8f\u5217\u4e2d\u3002<\/p>\n<h1 id=\"\uff12\u6027\u80fd\"><a name=\"t33\"><\/a><a target=\"_blank\" name=\"t33\"><\/a>\uff12.\u6027\u80fd<\/h1>\n<p>\u6570\u636e\u7ed3\u6784\u00a0\u6570\u7ec4<br \/>\n\u6700\u5dee\u65f6\u95f4\u590d\u6742\u5ea6 \u3000 O(n^2)<br \/>\n\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6 \u3000O(n+k)<br \/>\n\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u3000O(n*k)<\/p>\n<p>\u5e73\u5747\u60c5\u51b5\u4e0b\u6876\u6392\u5e8f\u4ee5\u7ebf\u6027\u65f6\u95f4\u8fd0\u884c\uff0c\u6876\u6392\u5e8f\u662f\u7a33\u5b9a\u7684\uff0c\u6392\u5e8f\u975e\u5e38\u5feb,\u4f46\u662f\u540c\u65f6\u4e5f\u975e\u5e38\u8017\u7a7a\u95f4,\u57fa\u672c\u4e0a\u662f\u6700\u8017\u7a7a\u95f4\u7684\u4e00\u79cd\u6392\u5e8f\u7b97\u6cd5\u3002<\/p>\n<p>\u5bf9N\u4e2a\u5173\u952e\u5b57\u8fdb\u884c\u6876\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5206\u4e3a\u4e24\u4e2a\u90e8\u5206\uff1a<\/p>\n<p>\u2460\u5faa\u73af\u8ba1\u7b97\u6bcf\u4e2a\u5173\u952e\u5b57\u7684\u6876\u6620\u5c04\u51fd\u6570\uff0c\u8fd9\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(N)\u3002<\/p>\n<p>\u2461\u5229\u7528\u5148\u8fdb\u7684\u6bd4\u8f83\u6392\u5e8f\u7b97\u6cd5\u5bf9\u6bcf\u4e2a\u6876\u5185\u7684\u6240\u6709\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \u2211 O(Ni*logNi) \u3002\u5176\u4e2dNi \u4e3a\u7b2ci\u4e2a\u6876\u7684\u6570\u636e\u91cf\u3002<\/p>\n<p>\u5f88\u663e\u7136\uff0c\u7b2c\u2461\u90e8\u5206\u662f\u6876\u6392\u5e8f\u6027\u80fd\u597d\u574f\u7684\u51b3\u5b9a\u56e0\u7d20\u3002\u5c3d\u91cf\u51cf\u5c11\u6876\u5185\u6570\u636e\u7684\u6570\u91cf\u662f\u63d0\u9ad8\u6548\u7387\u7684\u552f\u4e00\u529e\u6cd5(\u56e0\u4e3a\u57fa\u4e8e\u6bd4\u8f83\u6392\u5e8f\u7684\u6700\u597d\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u53ea\u80fd\u8fbe\u5230O(N*logN)\u4e86)\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u9700\u8981\u5c3d\u91cf\u505a\u5230\u4e0b\u9762\u4e24\u70b9\uff1a<\/p>\n<blockquote><p>\u2460 \u6620\u5c04\u51fd\u6570f(k)\u80fd\u591f\u5c06N\u4e2a\u6570\u636e\u5e73\u5747\u7684\u5206\u914d\u5230M\u4e2a\u6876\u4e2d\uff0c\u8fd9\u6837\u6bcf\u4e2a\u6876\u5c31\u6709[N\/M]\u4e2a\u6570\u636e\u91cf\u3002<\/p>\n<p>\u2461\u5c3d\u91cf\u7684\u589e\u5927\u6876\u7684\u6570\u91cf\u3002\u6781\u9650\u60c5\u51b5\u4e0b\u6bcf\u4e2a\u6876\u53ea\u80fd\u5f97\u5230\u4e00\u4e2a\u6570\u636e\uff0c\u8fd9\u6837\u5c31\u5b8c\u5168\u907f\u5f00\u4e86\u6876\u5185\u6570\u636e\u7684\u201c\u6bd4\u8f83\u201d\u6392\u5e8f\u64cd\u4f5c\u3002 \u5f53\u7136\uff0c\u505a\u5230\u8fd9\u4e00\u70b9\u5f88\u4e0d\u5bb9\u6613\uff0c\u6570\u636e\u91cf\u5de8\u5927\u7684\u60c5\u51b5\u4e0b\uff0cf(k)\u51fd\u6570\u4f1a\u4f7f\u5f97\u6876\u96c6\u5408\u7684\u6570\u91cf\u5de8\u5927\uff0c\u7a7a\u95f4\u6d6a\u8d39\u4e25\u91cd\u3002\u8fd9\u5c31\u662f\u4e00\u4e2a\u65f6\u95f4\u4ee3\u4ef7\u548c\u7a7a\u95f4\u4ee3\u4ef7\u7684\u6743\u8861\u95ee\u9898\u4e86\u3002<\/p><\/blockquote>\n<h1 id=\"3java\u5b9e\u73b0\"><a name=\"t34\"><\/a><a target=\"_blank\" name=\"t34\"><\/a>3.java\u5b9e\u73b0<\/h1>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160607102041634\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5bf9\uff10\uff5e\uff11\u4e4b\u95f4\u7684\u4e00\u7ec4\u6d6e\u70b9\u6570\u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\uff1a<\/p>\n<p>BucketSort.java<\/p>\n<pre class=\"prettyprint\">&lt;code class=\"hljs java has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-class\" style=\"box-sizing: border-box;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;class&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box; color: rgb(102, 0, 102);\"&gt;BucketSort&lt;\/span&gt; {&lt;\/span&gt; &lt;span class=\"hljs-javadoc\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/** * \u5bf9arr\u8fdb\u884c\u6876\u6392\u5e8f\uff0c\u6392\u5e8f\u7ed3\u679c\u4ecd\u653e\u5728arr\u4e2d *\/&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;bucketSort&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;double&lt;\/span&gt; arr[]){ &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/-------------------------------------------------\u5206\u6876----------------------------------------------- &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; n = arr.length; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5b58\u653e\u6876\u7684\u94fe\u8868&lt;\/span&gt; ArrayList bucketList[] = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;new&lt;\/span&gt; ArrayList [n]; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u6bcf\u4e2a\u6876\u662f\u4e00\u4e2alist\uff0c\u5b58\u653e\u6b64\u6876\u7684\u5143\u7d20 &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i =&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;;i&lt;n;i++){ &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u4e0b\u53d6\u7b49&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; temp = (&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;) Math.floor(n*arr[i]); &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u82e5\u4e0d\u5b58\u5728\u8be5\u6876\uff0c\u5c31\u65b0\u5efa\u4e00\u4e2a\u6876\u5e76\u52a0\u5165\u5230\u6876\u94fe\u8868\u4e2d&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;null&lt;\/span&gt;==bucketList[temp]) bucketList[temp] = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;new&lt;\/span&gt; ArrayList(); &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u628a\u5f53\u524d\u5143\u7d20\u52a0\u5165\u5230\u5bf9\u5e94\u6876\u4e2d&lt;\/span&gt; bucketList[temp].add(arr[i]); } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/-------------------------------------------------\u6876\u5185\u6392\u5e8f----------------------------------------------- &lt;\/span&gt; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5bf9\u6bcf\u4e2a\u6876\u4e2d\u7684\u6570\u8fdb\u884c\u63d2\u5165\u6392\u5e8f &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;;i&lt;n;i++){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;null&lt;\/span&gt;!=bucketList[i]) insert(bucketList[i]); } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/-------------------------------------------------\u5408\u5e76\u6876\u5185\u6570\u636e----------------------------------------------- &lt;\/span&gt; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u628a\u5404\u4e2a\u6876\u7684\u6392\u5e8f\u7ed3\u679c\u5408\u5e76 &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; count = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;;i&lt;n;i++){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;null&lt;\/span&gt;!=bucketList[i]){ Iterator iter = bucketList[i].iterator(); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(iter.hasNext()){ Double d = (Double)iter.next(); arr[count] = d; count++; } } } } &lt;span class=\"hljs-javadoc\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/** * \u7528\u63d2\u5165\u6392\u5e8f\u5bf9\u6bcf\u4e2a\u6876\u8fdb\u884c\u6392\u5e8f * \u4ece\u5c0f\u5230\u5927\u6392\u5e8f *\/&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;insert&lt;\/span&gt;(ArrayList list){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(list.size()&gt;&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i =&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;;i&lt;list.size();i++){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;((Double)list.get(i)&lt;(Double)list.get(i-&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;)){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;double&lt;\/span&gt; temp = (Double) list.get(i); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; j = i-&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(;j&gt;=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;&amp;&amp;((Double)list.get(j)&gt;(Double)list.get(j+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;));j--) list.set(j+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;, list.get(j)); &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u540e\u79fb&lt;\/span&gt; list.set(j+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;, temp); } } } } }&lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;23&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;24&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;25&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;26&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;27&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;28&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;29&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;30&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;31&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;32&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;33&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;34&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;35&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;36&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;37&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;38&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;39&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;40&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;41&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;42&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;43&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;44&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;45&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;46&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;47&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;48&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;49&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;50&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;51&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;52&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;53&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;54&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;55&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;56&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;57&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;58&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;59&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<p>\u6d4b\u8bd5\u4ee3\u7801\uff1a<\/p>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cs has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;main&lt;\/span&gt;(String[] args) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;double&lt;\/span&gt; arr [] ={&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0.21&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0.23&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0.76&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0.12&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0.89&lt;\/span&gt;}; BucketSort.bucketSort(arr); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;double&lt;\/span&gt; a:arr){ System.&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;out&lt;\/span&gt;.println(a); } }&lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160607105154789\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u4e5d\u3001\u57fa\u6570\u6392\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"title-7\"><a target=\"_blank\" name=\"t35\"><\/a><\/h2>\n<h1 id=\"\u539f\u7406\"><a name=\"t36\"><\/a><a target=\"_blank\" name=\"t36\"><\/a>\u539f\u7406<\/h1>\n<p>\u57fa\u6570\u6392\u5e8f\uff08Radix sort\uff09\u662f\u4e00\u79cd\u975e\u6bd4\u8f83\u578b\u6574\u6570\u6392\u5e8f\u7b97\u6cd5\uff0c\u5176\u539f\u7406\u662f\u5c06\u6574\u6570\u6309\u4f4d\u6570\u5207\u5272\u6210\u4e0d\u540c\u7684\u6570\u5b57\uff0c\u7136\u540e\u6309\u6bcf\u4e2a\u4f4d\u6570\u5206\u522b\u6bd4\u8f83\u3002\u7531\u4e8e\u6574\u6570\u4e5f\u53ef\u4ee5\u8868\u8fbe\u5b57\u7b26\u4e32\uff08\u6bd4\u5982\u540d\u5b57\u6216\u65e5\u671f\uff09\u548c\u7279\u5b9a\u683c\u5f0f\u7684\u6d6e\u70b9\u6570\uff0c\u6240\u4ee5\u57fa\u6570\u6392\u5e8f\u4e5f\u4e0d\u662f\u53ea\u80fd\u4f7f\u7528\u4e8e\u6574\u6570\u3002<\/p>\n<p>\u5c06\u6240\u6709\u5f85\u6bd4\u8f83\u6570\u503c\uff08\u6b63\u6574\u6570\uff09\u7edf\u4e00\u4e3a\u540c\u6837\u7684\u6570\u4f4d\u957f\u5ea6\uff0c\u6570\u4f4d\u8f83\u77ed\u7684\u6570\u524d\u9762\u8865\u96f6\u3002\u7136\u540e\uff0c\u4ece\u6700\u4f4e\u4f4d\u5f00\u59cb\uff0c\u4f9d\u6b21\u8fdb\u884c\u4e00\u6b21\u6392\u5e8f\u3002\u8fd9\u6837\u4ece\u6700\u4f4e\u4f4d\u6392\u5e8f\u4e00\u76f4\u5230\u6700\u9ad8\u4f4d\u6392\u5e8f\u5b8c\u6210\u4ee5\u540e\uff0c\u6570\u5217\u5c31\u53d8\u6210\u4e00\u4e2a\u6709\u5e8f\u5e8f\u5217\u3002<\/p>\n<h1 id=\"\u6548\u7387\"><a name=\"t37\"><\/a><a target=\"_blank\" name=\"t37\"><\/a>\u6548\u7387<\/h1>\n<p>\u57fa\u6570\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662fO(k\u00b7n)\uff0c\u5176\u4e2dn\u662f\u6392\u5e8f\u5143\u7d20\u4e2a\u6570\uff0ck\u662f\u6570\u5b57\u4f4d\u6570\u3002\u6ce8\u610f\u8fd9\u4e0d\u662f\u8bf4\u8fd9\u4e2a\u65f6\u95f4\u590d\u6742\u5ea6\u4e00\u5b9a\u4f18\u4e8eO(n\u00b7log(n))\uff0ck\u7684\u5927\u5c0f\u53d6\u51b3\u4e8e\u6570\u5b57\u4f4d\u7684\u9009\u62e9\u548c\u5f85\u6392\u5e8f\u6570\u636e\u6240\u5c5e\u6570\u636e\u7c7b\u578b\u7684\u5168\u96c6\u7684\u5927\u5c0f\uff1bk\u51b3\u5b9a\u4e86\u8fdb\u884c\u591a\u5c11\u8f6e\u5904\u7406\uff0c\u800cn\u662f\u6bcf\u8f6e\u5904\u7406\u7684\u64cd\u4f5c\u6570\u76ee\u3002<\/p>\n<p>\u57fa\u6570\u6392\u5e8f\u57fa\u672c\u64cd\u4f5c\u7684\u4ee3\u4ef7\u8f83\u5c0f\uff0ck\u4e00\u822c\u4e0d\u5927\u4e8elogn\uff0c\u6240\u4ee5\u57fa\u6570\u6392\u5e8f\u4e00\u822c\u8981\u5feb\u8fc7\u57fa\u4e8e\u6bd4\u8f83\u7684\u6392\u5e8f\uff0c\u6bd4\u5982\u5feb\u901f\u6392\u5e8f\u3002<\/p>\n<p>\u6700\u5dee\u7a7a\u95f4\u590d\u6742\u5ea6\u662fO(k\u00b7n)<\/p>\n<h1 id=\"java\u5b9e\u73b0-3\"><a name=\"t38\"><\/a><a target=\"_blank\" name=\"t38\"><\/a>Java\u5b9e\u73b0<\/h1>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160607115546499\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u73b0\u5728\u6709\u6570\u7ec4\uff1a278\uff0c109\uff0c63,930,589,184,505,269,8,83\u3000\u3002\u6839\u636e\u5404\u4f4d\u6570\u5c06\u6570\u7ec4\u5212\u5206\u4e3a10\u4e2a\u94fe\u8868(\u5f53\u7136\u5176\u4e2d\u7684\u67d0\u4e9b\u94fe\u8868\u53ef\u80fd\u4e0d\u542b\u6709\u5143\u7d20)<\/p>\n<p>\u7b2c\u4e00\u6b21\u5206\u914d\uff1a<\/p>\n<blockquote><p>0:930<br \/>\n1:<br \/>\n2:<br \/>\n3:63,83<br \/>\n4:184<br \/>\n5:505<br \/>\n6\uff1a<br \/>\n7:<br \/>\n8:278,8<br \/>\n9:109,589,269<\/p><\/blockquote>\n<p>\u7b2c\u4e00\u6b21\u6536\u96c6\u540e\u7684\u6570\u7ec4\uff1a<\/p>\n<blockquote><p>930,63,83,184,505\uff0c278,8,109,589,269<\/p><\/blockquote>\n<p>\u7b2c\u4e8c\u6b21\u5206\u914d\uff1a<\/p>\n<blockquote><p>0:505,8,109<br \/>\n1:<br \/>\n2:<br \/>\n3:930<br \/>\n4:<br \/>\n5:<br \/>\n6\uff1a63,269<br \/>\n7:278<br \/>\n8:83,184\uff0c589<br \/>\n9:<\/p><\/blockquote>\n<p>\u7b2c\u4e8c\u6b21\u6536\u96c6\u540e\u7684\u6570\u7ec4\uff1a<\/p>\n<blockquote><p>505,8,109\uff0c930\uff0c63,269\uff0c278\uff0c83,184\uff0c589<\/p><\/blockquote>\n<p>\u7b2c\u4e09\u6b21\u5206\u914d\uff1a<\/p>\n<blockquote><p>0:8,63,83<br \/>\n1:109,184<br \/>\n2:278,269<br \/>\n3:<br \/>\n4:<br \/>\n5:505,589<br \/>\n6:<br \/>\n7:<br \/>\n8:<br \/>\n9:930<\/p><\/blockquote>\n<p>\u6700\u540e\u5f97\u5230\u5e8f\u5217\uff1a<\/p>\n<blockquote><p>8,63,83,109,184\uff0c269,278,505,589,930<\/p><\/blockquote>\n<p>\u57fa\u6570\u6392\u5e8f\u5176\u5b9e\u662f\u5229\u7528\u591a\u5173\u952e\u5b57\u5148\u8fbe\u5230\u5c40\u90e8\u6709\u5e8f\uff0c\u518d\u8c03\u6574\u8fbe\u5230\u5168\u5c40\u6709\u5e8f\u3002<\/p>\n<p>\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cpp has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;class&lt;\/span&gt; Test { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; main(String[] args) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt; = {&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;278&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;109&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;63&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;930&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;589&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;184&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;505&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;269&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;8&lt;\/span&gt;,&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;83&lt;\/span&gt;}; radixSort(&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;double&lt;\/span&gt; a : &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;){ System.out.println(a); } } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; radixSort(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;){ &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/------------------------------------------\u786e\u5b9a\u6392\u5e8f\u7684\u8d9f\u6570----------------------------------&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; max=&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;[&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;]; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;;i&lt;&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;.length;i++){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;[i]&gt;max){ max=&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;[i]; } } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; time=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(max&gt;&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;){ max\/=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;10&lt;\/span&gt;; time++; } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/----------------------------------------\u521d\u59cb\u531610\u4e2a\u94fe\u8868\u7528\u6237\u5206\u914d\u65f6\u6682\u5b58-------------------------------&lt;\/span&gt; List&lt;List&lt;Integer&gt;&gt; &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;=&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;new&lt;\/span&gt; ArrayList&lt;List&lt;Integer&gt;&gt;(); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;;i&lt;&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;10&lt;\/span&gt;;i++){ List&lt;Integer&gt; item=&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;new&lt;\/span&gt; ArrayList&lt;Integer&gt;(); &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;.add(item); } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/-----------------------------------------\u8fdb\u884ctime\u6b21\u5206\u914d\u548c\u6536\u96c6-------------------------------------&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;;i&lt;time;i++){ &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5206\u914d\u5143\u7d20;&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; j=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;;j&lt;&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;.length;j++){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; index = &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;[j]%(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;)Math.&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;pow&lt;\/span&gt;(&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;10&lt;\/span&gt;, i+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;)\/(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;)Math.&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;pow&lt;\/span&gt;(&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;10&lt;\/span&gt;, i); &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;.get(index).add(&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;[j]); } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u6536\u96c6\u5143\u7d20;&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; count=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; k=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;;k&lt;&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;10&lt;\/span&gt;;k++){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;.get(k).size()&gt;&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; a : &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;.get(k)){ &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;array&lt;\/span&gt;[count]=a; count++; } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u6e05\u9664\u6570\u636e\uff0c\u4ee5\u4fbf\u4e0b\u6b21\u6536\u96c6&lt;\/span&gt; &lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;list&lt;\/span&gt;.get(k).clear(); } } } } }&lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;23&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;24&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;25&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;26&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;27&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;28&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;29&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;30&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;31&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;32&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;33&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;34&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;35&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;36&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;37&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;38&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;39&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;40&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;41&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;42&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;43&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;44&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;45&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;46&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;47&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;48&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;49&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;50&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;51&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;52&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20160607135057719\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u5341\u3001\u63d2\u5165\u6392\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"title-8\"><a target=\"_blank\" name=\"t39\"><\/a><\/h2>\n<h1 id=\"\u6982\u8ff0-2\"><a name=\"t40\"><\/a><a target=\"_blank\" name=\"t40\"><\/a>\u6982\u8ff0<\/h1>\n<p>\u5c06\u4e00\u4e2a\u6570\u636e\u63d2\u5165\u5230\u5df2\u7ecf\u6392\u597d\u5e8f\u7684\u6709\u5e8f\u6570\u636e\u4e2d\uff0c\u4ece\u800c\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u3001\u4e2a\u6570\u52a0\u4e00\u7684\u6709\u5e8f\u6570\u636e\uff0c\u7b97\u6cd5\u9002\u7528\u4e8e\u5c11\u91cf\u6570\u636e\u7684\u6392\u5e8f\uff0c\u662f\u7a33\u5b9a\u7684\u6392\u5e8f\u65b9\u6cd5\u3002<\/p>\n<p>\u63d2\u5165\u6392\u5e8f\u53c8\u5206\u4e3a\u3000\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u3000\u548c \u6298\u534a\u63d2\u5165\u6392\u5e8f\u3002<\/p>\n<h1 id=\"\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\"><a name=\"t41\"><\/a><a target=\"_blank\" name=\"t41\"><\/a>\u76f4\u63a5\u63d2\u5165\u6392\u5e8f<\/h1>\n<p>\u628a\u5f85\u6392\u5e8f\u7684\u7eaa\u5f55\u6309\u5176\u5173\u952e\u7801\u503c\u7684\u5927\u5c0f\u9010\u4e2a\u63d2\u5165\u5230\u4e00\u4e2a\u5df2\u7ecf\u6392\u597d\u5e8f\u7684\u6709\u5e8f\u5e8f\u5217\u4e2d\uff0c\u76f4\u5230\u6240\u6709\u7684\u7eaa\u5f55\u63d2\u5165\u5b8c\u4e3a\u6b62\uff0c\u5f97\u5230\u4e00\u4e2a\u65b0\u7684\u6709\u5e8f\u5e8f\u5217\u3002<\/p>\n<h2 id=\"java\u5b9e\u73b0-4\"><a name=\"t42\"><\/a><a target=\"_blank\" name=\"t42\"><\/a>Java\u5b9e\u73b0<\/h2>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cs has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;void&lt;\/span&gt; &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;insertSort&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; a[]){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; j; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5f53\u524d\u8981\u63d2\u5165\u503c\u7684\u4f4d\u7f6e &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; preJ; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u4f9d\u6b21\u6307\u5411j\u524d\u7684\u4f4d\u7f6e &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; key; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u540e\u79fb\u65f6\u6765\u6682\u5b58\u8981\u63d2\u5165\u7684\u503c&lt;\/span&gt; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u4ece\u6570\u7ec4\u7684\u7b2c\u4e8c\u4e2a\u4f4d\u7f6e\u5f00\u59cb\u904d\u5386\u503c &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(j=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;;j&lt;a.length;j++){ key=a[j]; preJ=j-&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/a[preJ]\u6bd4\u5f53\u524d\u503c\u5927\u65f6\uff0ca[preJ]\u540e\u79fb\u4e00\u4f4d &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(preJ&gt;=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt; &amp;&amp; a[preJ]&gt;key){ a[preJ+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;]=a[preJ]; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5c06a[preJ]\u503c\u540e\u79fb &lt;\/span&gt; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u8fd9\u91cc\u6ce8\u610f: a[preJ+1]=a[j]=key,\u628a\u63d2\u5165\u503c\u5df2\u7ecf\u5b58\u5728\u4e86 key\u4e2d&lt;\/span&gt; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u7b49\u4e8e\u8bf4, \u7559\u51fa\u6765\u4e00\u4e2a\u7a7a\u767d\u4f4d\u7f6e\u6765\u5b9e\u73b0\u4f9d\u6b21\u540e\u79fb\uff08\u4e0d\u4f1a\u9020\u6210\u6570\u636e\u4e22\u5931\u95ee\u9898\uff09&lt;\/span&gt; preJ--; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/preJ\u524d\u79fb &lt;\/span&gt; } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u627e\u5230\u8981\u63d2\u5165\u7684\u4f4d\u7f6e\u6216\u5df2\u904d\u5386\u5b8c\u6210\uff08(preJ=0\uff09&lt;\/span&gt; a[preJ+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;]=key; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u5c06\u5f53\u524d\u503c\u63d2\u5165 \u7a7a\u767d\u4f4d\u7f6e&lt;\/span&gt; } } &lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<p>\u5907\u6ce8\u5f88\u6e05\u695a\uff0c\u6211\u5c31\u4e0d\u591a\u8bf4\u4e86\uff0e\uff0e\uff0e\uff0e<\/p>\n<h2 id=\"\u6548\u7387\u5206\u6790\"><a name=\"t43\"><\/a><a target=\"_blank\" name=\"t43\"><\/a>\u6548\u7387\u5206\u6790<\/h2>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6O(1)<\/p>\n<p>\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6O(n^2)<\/p>\n<blockquote><p>\u6700\u5dee\u60c5\u51b5\uff1a\u53cd\u5e8f\uff0c\u9700\u8981\u79fb\u52a8n*(n-1)\/2\u4e2a\u5143\u7d20 \uff0c\u8fd0\u884c\u65f6\u95f4\u4e3aO(n^2)\u3002<\/p>\n<p>\u6700\u597d\u60c5\u51b5\uff1a\u6b63\u5e8f\uff0c\u4e0d\u9700\u8981\u79fb\u52a8\u5143\u7d20\uff0c\u8fd0\u884c\u65f6\u95f4\u4e3aO(n)\uff0e<\/p><\/blockquote>\n<h1 id=\"\u6298\u534a\u63d2\u5165\u6392\u5e8f\"><a name=\"t44\"><\/a><a target=\"_blank\" name=\"t44\"><\/a>\u6298\u534a\u63d2\u5165\u6392\u5e8f<\/h1>\n<p>\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u4e2d\u8981\u628a\u63d2\u5165\u5143\u7d20\u4e0e\u5df2\u6709\u5e8f\u5e8f\u5217\u5143\u7d20\u4f9d\u6b21\u8fdb\u884c\u6bd4\u8f83\uff0c\u6548\u7387\u975e\u5e38\u4f4e\u3002<\/p>\n<p>\u6298\u534a\u63d2\u5165\u6392\u5e8f,\u4f7f\u7528\u4f7f\u7528\u6298\u534a\u67e5\u627e\u7684\u65b9\u5f0f\u5bfb\u627e\u63d2\u5165\u70b9\u7684\u4f4d\u7f6e, \u53ef\u4ee5\u51cf\u5c11\u6bd4\u8f83\u7684\u6b21\u6570,\u4f46\u79fb\u52a8\u7684\u6b21\u6570\u4e0d\u53d8, \u65f6\u95f4\u590d\u6742\u5ea6\u548c\u7a7a\u95f4\u590d\u6742\u5ea6\u548c\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u4e00\u6837\uff0c\u5728\u5143\u7d20\u8f83\u591a\u7684\u60c5\u51b5\u4e0b\u80fd\u63d0\u9ad8\u67e5\u627e\u6027\u80fd\u3002<\/p>\n<h2 id=\"java\u5b9e\u73b0-5\"><a name=\"t45\"><\/a><a target=\"_blank\" name=\"t45\"><\/a>Java\u5b9e\u73b0<\/h2>\n<pre class=\"prettyprint\">&lt;code class=\"hljs livecodeserver has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;private&lt;\/span&gt; static void binaryInsertSort(int[] &lt;span class=\"hljs-operator\" style=\"box-sizing: border-box;\"&gt;a&lt;\/span&gt;) { &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt; \/\/\u4ece\u6570\u7ec4\u7684\u7b2c\u4e8c\u4e2a\u4f4d\u7f6e\u5f00\u59cb\u904d\u5386\u503c &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(int i = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; i &lt; &lt;span class=\"hljs-operator\" style=\"box-sizing: border-box;\"&gt;a&lt;\/span&gt;.&lt;span class=\"hljs-built_in\" style=\"color: rgb(102, 0, 102); box-sizing: border-box;\"&gt;length&lt;\/span&gt;; i++) { int key = &lt;span class=\"hljs-operator\" style=\"box-sizing: border-box;\"&gt;a&lt;\/span&gt;[i]; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt; \/\/\u6682\u5b58\u8981\u63d2\u5165\u7684\u503c &lt;\/span&gt; int pre = &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt; \/\/\u6709\u5e8f\u5e8f\u5217\u5f00\u59cb\u548c\u7ed3\u5c3e\u4e0b\u6807\u7533\u660e&lt;\/span&gt; int &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;last&lt;\/span&gt; = i - &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt; \/\/ \u6298\u534a\u67e5\u627e\u51fa\u63d2\u5165\u4f4d\u7f6e a[pre]&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(pre &lt;= &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;last&lt;\/span&gt;) { int &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;mid&lt;\/span&gt; = (pre + &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;last&lt;\/span&gt;) \/ &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;2&lt;\/span&gt;; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(key &lt; &lt;span class=\"hljs-operator\" style=\"box-sizing: border-box;\"&gt;a&lt;\/span&gt;[&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;mid&lt;\/span&gt;]) { &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;last&lt;\/span&gt; = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;mid&lt;\/span&gt; - &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;else&lt;\/span&gt; { pre = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;mid&lt;\/span&gt; + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; } } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt; \/\/a[i]\u5df2\u7ecf\u53d6\u51fa\u6765\u5b58\u653e\u5728key\u4e2d\uff0c\u628a\u4e0b\u6807\u4ecepre + 1\u5230 i-1\u7684\u5143\u7d20\u4f9d\u6b21\u540e\u79fb&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(int j = i; j &gt;= pre + &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;; j&lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;--) { &lt;\/span&gt; &lt;span class=\"hljs-operator\" style=\"box-sizing: border-box;\"&gt;a&lt;\/span&gt;[j] = &lt;span class=\"hljs-operator\" style=\"box-sizing: border-box;\"&gt;a&lt;\/span&gt;[j - &lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;]; } &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt; \/\/\u628a\u503c\u63d2\u5165\u7a7a\u767d\u4f4d\u7f6e&lt;\/span&gt; &lt;span class=\"hljs-operator\" style=\"box-sizing: border-box;\"&gt;a&lt;\/span&gt;[pre] = key; } } &lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;23&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;24&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<p>\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u662f\uff0c\u6bd4\u8f83\u4e00\u4e2a\u540e\u79fb\u4e00\u4e2a\uff1b<br \/>\n\u6298\u534a\u63d2\u5165\u6392\u5e8f\u662f\uff0c\u5148\u627e\u5230\u4f4d\u7f6e\uff0c\u7136\u540e\u4e00\u8d77\u79fb\u52a8\uff1b<\/p>\n<table>\n<tbody>\n<tr>\n<td bgcolor=\"#f4f31a\">\u5341\u4e00\u3001\u8865\u5145<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"1-\u5feb\u6392\u7684partition\u51fd\u6570\"><a name=\"t46\"><\/a><a target=\"_blank\" name=\"t46\"><\/a>1. \u5feb\u6392\u7684partition\u51fd\u6570<\/h3>\n<p>\u4f5c\u7528\uff1a\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4arr[]\u548c\u6570\u7ec4\u4e2d\u4efb\u610f\u4e00\u4e2a\u5143\u7d20a\uff0c\u91cd\u6392\u6570\u7ec4\u4f7f\u5f97a\u5de6\u8fb9\u90fd\u5c0f\u4e8e\u5b83\uff0c\u53f3\u8fb9\u90fd\u4e0d\u5c0f\u4e8e\u5b83\u3002<\/p>\n<pre class=\"prettyprint\">&lt;code class=\"hljs cs has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt;&lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/ A[]\u4e3a\u6570\u7ec4\uff0cstart\u3001end\u5206\u522b\u4e3a\u6570\u7ec4\u7b2c\u4e00\u4e2a\u5143\u7d20\u548c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15&lt;\/span&gt; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/ povitIndex\u4e3a\u6570\u7ec4\u4e2d\u4efb\u610f\u9009\u4e2d\u7684\u6570\u7684\u7d22\u5f15&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; partition(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; A[], &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; start, &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; end, &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; pivotIndex){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; i = start, j = end, pivot = A[pivotIndex]; swap&lt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;&gt;(A[end], A[pivotIndex]); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(i &lt; j){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(i &lt; j &amp;&amp; A[i] &lt;= pivot) ++i; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(i &lt; j &amp;&amp; A[j] &gt;= pivot) --j; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(i &lt; j) swap&lt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;&gt;(A[i], A[j]); } swap&lt;&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;&gt;(A[end], A[i]); &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;return&lt;\/span&gt; i; }&lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<h3 id=\"2-\u5192\u6ce1\u6392\u5e8f\u7684\u6539\u8fdb\"><a name=\"t47\"><\/a><a target=\"_blank\" name=\"t47\"><\/a>2. \u5192\u6ce1\u6392\u5e8f\u7684\u6539\u8fdb<\/h3>\n<p>\u601d\u8def\uff1a<\/p>\n<p>\u2460\u3001\u52a0\u4e00\u4e2a\u6807\u5fd7\u4f4d\uff0c\u5f53\u67d0\u4e00\u8d9f\u5192\u6ce1\u6392\u5e8f\u6ca1\u6709\u5143\u7d20\u4ea4\u6362\u65f6\uff0c\u5219\u5192\u6ce1\u7ed3\u675f\uff0c\u5143\u7d20\u5df2\u7ecf\u6709\u5e8f\uff0c\u53ef\u4ee5\u6709\u6548\u7684\u51cf\u5c11\u5192\u6ce1\u6b21\u6570\u3002<\/p>\n<pre class=\"prettyprint\">&lt;code class=\"hljs java has-numbering\" style=\"display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: \"Source Code Pro\", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;\"&gt; &lt;span class=\"hljs-javadoc\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/** * \u5f15\u5165\u6807\u5fd7\u4f4d\uff0c\u9ed8\u8ba4\u4e3atrue * \u5982\u679c\u524d\u540e\u6570\u636e\u8fdb\u884c\u4e86\u4ea4\u6362\uff0c\u5219\u4e3atrue\uff0c\u5426\u5219\u4e3afalse\u3002\u5982\u679c\u6ca1\u6709\u6570\u636e\u4ea4\u6362\uff0c\u5219\u6392\u5e8f\u5b8c\u6210\u3002 *\/&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;public&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;static&lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] &lt;span class=\"hljs-title\" style=\"box-sizing: border-box;\"&gt;bubbleSort&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt;[] arr){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;boolean&lt;\/span&gt; flag = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;true&lt;\/span&gt;; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; n = arr.length; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;while&lt;\/span&gt;(flag){ flag = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;false&lt;\/span&gt;; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;for&lt;\/span&gt;(&lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; j=&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;0&lt;\/span&gt;;j&lt;n-&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;;j++){ &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;if&lt;\/span&gt;(arr[j] &gt;arr[j+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;]){ &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u6570\u636e\u4ea4\u6362 &lt;\/span&gt; &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;int&lt;\/span&gt; temp = arr[j]; arr[j] = arr[j+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;]; arr[j+&lt;span class=\"hljs-number\" style=\"color: rgb(0, 102, 102); box-sizing: border-box;\"&gt;1&lt;\/span&gt;] = temp; &lt;span class=\"hljs-comment\" style=\"color: rgb(136, 0, 0); box-sizing: border-box;\"&gt;\/\/\u8bbe\u7f6e\u6807\u5fd7\u4f4d &lt;\/span&gt; flag = &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;true&lt;\/span&gt;; } } n--; } &lt;span class=\"hljs-keyword\" style=\"color: rgb(0, 0, 136); box-sizing: border-box;\"&gt;return&lt;\/span&gt; arr; } &lt;\/code&gt;&lt;ul class=\"pre-numbering\" style=\"box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);\"&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;1&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;2&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;3&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;4&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;5&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;6&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;7&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;8&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;9&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;10&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;11&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;12&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;13&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;14&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;15&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;16&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;17&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;18&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;19&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;20&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;21&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;22&lt;\/li&gt;&lt;li style=\"box-sizing: border-box; padding: 0px 5px;\"&gt;23&lt;\/li&gt;&lt;\/ul&gt;<\/pre>\n<p>\u2461\u3001\u8bb0\u5f55\u6bcf\u4e00\u6b21\u5143\u7d20\u4ea4\u6362\u7684\u4f4d\u7f6e\uff0c\u5f53\u5143\u7d20\u4ea4\u6362\u7684\u4f4d\u7f6e\u5728\u7b2c0\u4e2a\u5143\u7d20\u65f6\uff0c\u5219\u6392\u5e8f\u7ed3\u675f\u3002<\/p>\n<h3 id=\"3\u5feb\u6392\u4f18\u5316\"><a name=\"t48\"><\/a><a target=\"_blank\" name=\"t48\"><\/a>3.\u5feb\u6392\u4f18\u5316<\/h3>\n<p>\u2460 \u5feb\u901f\u6392\u5e8f\u5728\u5904\u7406\u5c0f\u89c4\u6a21\u6570\u636e\u65f6\u7684\u8868\u73b0\u4e0d\u597d\uff0c\u8fd9\u4e2a\u65f6\u5019\u53ef\u4ee5\u6539\u7528\u63d2\u5165\u6392\u5e8f\u3002<\/p>\n<p>\u2461\u5bf9\u4e8e\u4e00\u4e2a\u6bcf\u4e2a\u5143\u7d20\u90fd\u5b8c\u5168\u76f8\u540c\u7684\u4e00\u4e2a\u5e8f\u5217\u6765\u8bb2\uff0c\u5feb\u901f\u6392\u5e8f\u4e5f\u4f1a\u9000\u5316\u5230 O(n^2)\u3002\u8981\u5c06\u8fd9\u79cd\u60c5\u51b5\u907f\u514d\u5230\uff0c\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<\/p>\n<p>\u5728\u5206\u533a\u7684\u65f6\u5019\uff0c\u5c06\u5e8f\u5217\u5206\u4e3a 3 \u5806\uff0c\u4e00\u5806\u5c0f\u4e8e\u4e2d\u8f74\u5143\u7d20\uff0c\u4e00\u5806\u7b49\u4e8e\u4e2d\u8f74\u5143\u7d20\uff0c\u4e00\u5806\u5927\u4e8e\u4e2d\u8f74\u5143\u7d20\uff0c\u4e0b\u6b21\u9012\u5f52\u8c03\u7528\u5feb\u901f\u6392\u5e8f\u7684\u65f6\u5019\uff0c\u53ea\u9700\u5bf9\u5c0f\u4e8e\u548c\u5927\u4e8e\u4e2d\u8f74\u5143\u7d20\u7684\u4e24\u5806\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u4e2d\u95f4\u7b49\u4e8e\u4e2d\u8f74\u5143\u7d20\u7684\u4e00\u5806\u5df2\u7ecf\u653e\u597d\u3002<\/p>\n<\/div>\n<\/div>\n<\/article>\n<\/div>\n<div class=\"t0 clearfix\">\n<div class=\"text-content\">\n<h4>\u5404\u79cd<em>\u6392\u5e8f<\/em>\u7b97\u6cd5\u7684\u5206\u6790\u53cajava\u5b9e\u73b0<\/h4>\n<div class=\"description\">\u6392\u5e8f\u4e00\u76f4\u4ee5\u6765\u90fd\u662f\u8ba9\u6211\u5f88\u5934\u75bc\u7684\u4e8b\uff0c\u4ee5\u524d\u4e0a\u300a\u6570\u636e\u7ed3\u6784\u300b\u6253\u9171\u6cb9\u53bb\u4e86\uff0c\u6574\u4e2a\u5b66\u671f\u4e0b\u6765\u624d\u52c9\u5f3a\u80fd\u5199\u51fa\u4e2a\u5192\u6ce1\u6392\u5e8f\u3002\u7531\u4e8e\u4e0b\u534a\u5e74\u8981\u51c6\u5907\u5de5\u4f5c\u4e86\uff0c\u4e5f\u77e5\u9053\u6392\u5e8f\u7b97\u6cd5\u7684\u91cd\u8981\u6027\uff08\u636e\u8bf4\u662f\u9762\u8bd5\u5fc5\u95ee\u7684\u77e5\u8bc6\u70b9\uff09\uff0c\u6240\u4ee5\u53c8\u82b1\u4e86\u70b9\u65f6\u95f4\u91cd\u65b0\u7814\u7a76\u4e86\u4e00&#8230;<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/blog.csdn.net<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[119],"class_list":["post-1718","post","type-post","status-publish","format-standard","hentry","tag-03-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=1718"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/1718\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=1718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=1718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=1718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}