{"id":154,"date":"2022-02-07T15:09:59","date_gmt":"2022-02-07T07:09:59","guid":{"rendered":"http:\/\/nas.hepcloud.top:7000\/?p=154"},"modified":"2022-11-01T23:48:17","modified_gmt":"2022-11-01T15:48:17","slug":"%e5%90%84%e7%a7%8d%e7%bb%8f%e5%85%b8%e6%8e%92%e5%ba%8f%e7%ae%97%e6%b3%95%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"http:\/\/www.huerpu.cc:7000\/?p=154","title":{"rendered":"\u5404\u79cd\u7ecf\u5178\u6392\u5e8f\u7b97\u6cd5\u8be6\u89e3"},"content":{"rendered":"<h3>\u5404\u79cd\u7ecf\u5178\u6392\u5e8f\u7b97\u6cd5\u8be6\u89e3<\/h3>\n<p><strong>\u2460\u6392\u5e8f\u7684\u5206\u7c7b<\/strong><\/p>\n<p>\u6309\u7167\u5b58\u50a8\u4ecb\u8d28\u6765\u5206\uff0c\u53ef\u4ee5\u5206\u4e3a\u5185\u90e8\u6392\u5e8f\u548c\u5916\u90e8\u6392\u5e8f\u3002<\/p>\n<ul>\n<li><strong>\u5185\u90e8\u6392\u5e8f<\/strong>\uff1a\u6570\u636e\u4e00\u76f4\u5728\u5185\u5b58\u4e2d\u8fdb\u884c\u7684\u6392\u5e8f\u79f0\u4e3a\u5185\u90e8\u6392\u5e8f\u3002<\/li>\n<li><strong>\u5916\u90e8\u6392\u5e8f<\/strong>\uff1a\u5f53\u6570\u636e\u91cf\u5f88\u5927\u65f6\u65e0\u6cd5\u5168\u90e8\u62f7\u8d1d\u5230\u5185\u5b58\u9700\u8981\u4f7f\u7528\u5916\u5b58\u7684\u65f6\u5019\uff0c\u79f0\u4e3a\u5916\u90e8\u6392\u5e8f\u3002<\/li>\n<\/ul>\n<p>\u6309\u7167\u6392\u5e8f\u7684\u7279\u70b9\u6765\u5206\uff0c\u5185\u90e8\u6392\u5e8f\u5305\u62ec\u6bd4\u8f83\u6392\u5e8f\u548c\u975e\u6bd4\u8f83\u6392\u5e8f\u3002<\/p>\n<ul>\n<li><strong>\u6bd4\u8f83\u7c7b\u6392\u5e8f<\/strong>\uff1a\u901a\u8fc7\u6bd4\u8f83\u6765\u51b3\u5b9a\u5143\u7d20\u95f4\u7684\u76f8\u5bf9\u6b21\u5e8f\uff0c\u7531\u4e8e\u5176\u65f6\u95f4\u590d\u6742\u5ea6\u4e0d\u80fd\u7a81\u7834O(nlogn)\uff0c\u56e0\u6b64\u4e5f\u79f0\u4e3a\u975e\u7ebf\u6027\u65f6\u95f4\u6bd4\u8f83\u7c7b\u6392\u5e8f\u3002<\/li>\n<li><strong>\u975e\u6bd4\u8f83\u7c7b\u6392\u5e8f<\/strong>\uff1a\u4e0d\u901a\u8fc7\u6bd4\u8f83\u6765\u51b3\u5b9a\u5143\u7d20\u95f4\u7684\u76f8\u5bf9\u6b21\u5e8f\uff0c\u5b83\u53ef\u4ee5\u7a81\u7834\u57fa\u4e8e\u6bd4\u8f83\u6392\u5e8f\u7684\u65f6\u95f4\u4e0b\u754c\uff0c\u4ee5\u7ebf\u6027\u65f6\u95f4\u8fd0\u884c\uff0c\u56e0\u6b64\u4e5f\u79f0\u4e3a\u7ebf\u6027\u65f6\u95f4\u975e\u6bd4\u8f83\u7c7b\u6392\u5e8f\u3002 <\/li>\n<\/ul>\n<p>\u6bd4\u8f83\u6392\u5e8f\u5305\u62ec\u63d2\u5165\/\u9009\u62e9\/\u4ea4\u6362\/\u5f52\u5e76\u6392\u5e8f\uff0c\u975e\u6bd4\u8f83\u6392\u5e8f\u5305\u62ec\u8ba1\u6570\/\u57fa\u6570\/\u6876\u6392\u5e8f\u3002\u63d2\u5165\u6392\u5e8f\u5305\u62ec\u76f4\u63a5\u63d2\u5165\/\u5e0c\u5c14\u6392\u5e8f\uff0c\u9009\u62e9\u6392\u5e8f\u5305\u62ec\u76f4\u63a5\u9009\u62e9\/\u5806\u6392\u5e8f\uff0c\u4ea4\u6362\u6392\u5e8f\u5305\u62ec\u5192\u6ce1\/\u5feb\u901f\u6392\u5e8f\u3002<\/p>\n<p>\u6309\u7167\u6570\u636e\u6392\u5e8f\u7684\u7a33\u5b9a\u6027\u6765\u5206\uff0c\u53ef\u4ee5\u5206\u4e3a\u7a33\u5b9a\u6392\u5e8f\u548c\u4e0d\u7a33\u5b9a\u6392\u5e8f\u3002<\/p>\n<ul>\n<li><strong>\u7a33\u5b9a<\/strong>\uff1a\u5982\u679c\u6570\u636em\u548cn\u76f8\u7b49\uff0c\u6392\u5e8f\u524dm\u5728n\u7684\u524d\u9762\uff0c\u6392\u5e8f\u540em\u4ecd\u5728n\u7684\u524d\u9762\uff0c\u5219\u79f0\u4e3a\u7a33\u5b9a\u6392\u5e8f\u3002<\/li>\n<li><strong>\u4e0d\u7a33\u5b9a<\/strong>\uff1a\u5982\u679c\u6570\u636em\u548cn\u76f8\u7b49\uff0c\u6392\u5e8f\u524dm\u5728n\u7684\u524d\u9762\uff0c\u6392\u5e8f\u540em\u53ef\u80fd\u4f1a\u51fa\u73b0\u5728 n\u7684\u540e\u9762\uff0c\u5219\u79f0\u4e3a\u4e0d\u7a33\u5b9a\u6392\u5e8f\u3002<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/sort-comparison.png\" alt=\"sort-comparison.png\" \/><\/p>\n<p><strong>\u2461\u5404\u6392\u5e8f\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u5bf9\u6bd4<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u6392\u5e8f\u7b97\u6cd5<\/th>\n<th style=\"text-align: center;\">\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6<\/th>\n<th style=\"text-align: center;\">\u6700\u597d\u60c5\u51b5<\/th>\n<th style=\"text-align: center;\">\u6700\u574f\u60c5\u51b5<\/th>\n<th style=\"text-align: center;\">\u7a7a\u95f4\u590d\u6742\u5ea6<\/th>\n<th style=\"text-align: center;\">\u6392\u5e8f\u65b9\u5f0f<\/th>\n<th style=\"text-align: center;\">\u7a33\u5b9a\u6027<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">\u5192\u6ce1\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n<sup>2<\/sup>)<\/td>\n<td style=\"text-align: center;\">O(n)<\/td>\n<td style=\"text-align: center;\">O(n<sup>2<\/sup>)<\/td>\n<td style=\"text-align: center;\">O(1)<\/td>\n<td style=\"text-align: center;\">\u5185\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u7a33\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u9009\u62e9\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n<sup>2<\/sup>)<\/td>\n<td style=\"text-align: center;\">O(n<sup>2<\/sup>)<\/td>\n<td style=\"text-align: center;\">O(n<sup>2<\/sup>)<\/td>\n<td style=\"text-align: center;\">O(1)<\/td>\n<td style=\"text-align: center;\">\u5185\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u4e0d\u7a33\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u63d2\u5165\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n<sup>2<\/sup>)<\/td>\n<td style=\"text-align: center;\">O(n)<\/td>\n<td style=\"text-align: center;\">O(n<sup>2<\/sup>)<\/td>\n<td style=\"text-align: center;\">O(1)<\/td>\n<td style=\"text-align: center;\">\u5185\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u7a33\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u5e0c\u5c14\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">O(n log<sup>2<\/sup>n)<\/td>\n<td style=\"text-align: center;\">O(n log<sup>2<\/sup>n)<\/td>\n<td style=\"text-align: center;\">O(1)<\/td>\n<td style=\"text-align: center;\">\u5185\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u4e0d\u7a33\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u5f52\u5e76\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">O(n)<\/td>\n<td style=\"text-align: center;\">\u5916\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u7a33\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u5feb\u901f\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">O(n<sup>2<\/sup>)<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">\u5185\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u4e0d\u7a33\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u5806\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">O(n log n)<\/td>\n<td style=\"text-align: center;\">O(1)<\/td>\n<td style=\"text-align: center;\">\u5185\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u4e0d\u7a33\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u8ba1\u6570\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n+k)<\/td>\n<td style=\"text-align: center;\">O(n+k)<\/td>\n<td style=\"text-align: center;\">O(n+k)<\/td>\n<td style=\"text-align: center;\">O(k)<\/td>\n<td style=\"text-align: center;\">\u5916\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u7a33\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u6876\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n+k)<\/td>\n<td style=\"text-align: center;\">O(n+k)<\/td>\n<td style=\"text-align: center;\">O(n<sup>2<\/sup>)<\/td>\n<td style=\"text-align: center;\">O(n+k)<\/td>\n<td style=\"text-align: center;\">\u5916\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u7a33\u5b9a<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u57fa\u6570\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">O(n*k)<\/td>\n<td style=\"text-align: center;\">O(n*k)<\/td>\n<td style=\"text-align: center;\">O(n*k)<\/td>\n<td style=\"text-align: center;\">O(n+k)<\/td>\n<td style=\"text-align: center;\">\u5916\u90e8\u6392\u5e8f<\/td>\n<td style=\"text-align: center;\">\u7a33\u5b9a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5176\u4e2d\uff0cn\u8868\u793a\u6570\u636e\u7684\u6570\u91cf\uff0ck\u8868\u793a\u6570\u636e\u7684\u4f4d\u6570\u3002<\/p>\n<p><strong>\u2462\u6392\u5e8f\u7b97\u6cd5\u601d\u60f3<\/strong><\/p>\n<h4><strong>\u5192\u6ce1\u6392\u5e8f(Bubble Sort)\u7684\u539f\u7406<\/strong><\/h4>\n<p>\u6bd4\u8f83\u76f8\u90bb\u7684\u5143\u7d20\uff0c\u5982\u679c\u7b2c\u4e00\u4e2a\u6bd4\u7b2c\u4e8c\u4e2a\u5927\u5c31\u8fdb\u884c\u4ea4\u6362\uff0c\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\uff0c\u6bcf\u4e00\u8f6e\u6392\u5e8f\u540e\u672b\u5c3e\u5143\u7d20\u90fd\u662f\u6709\u5e8f\u7684\uff0c\u8fd9\u6837\u5143\u7d20\u8d8a\u5927\u7684\u5143\u7d20\u5c31\u4f1a\u7ecf\u7531\u4ea4\u6362\u6162\u6162\u201c\u6c89\u201d\u5230\u6570\u636e\u7684\u5c3e\u7aef\uff0c\u5e76\u4e14\u6392\u5e8f\u7684\u65e0\u5e8f\u6570\u636e\u6bcf\u6b21\u51cf\u5c11\u4e00\u4e2a(\u672b\u5c3e\u6709\u5e8f\u7684\u4e00\u4e2a)\uff0c\u9488\u5bf9 n \u4e2a\u5143\u7d20\u91cd\u590d\u4ee5\u4e0a\u6b65\u9aa4 n &#8211; 1 \u6b21\u6392\u5e8f\u5b8c\u6bd5\u3002<\/p>\n<pre><code>public void bubbleSort(int[] nums) {\n    for (int i = 0; i &lt; nums.length - 1; i++) {\n        for (int index = 0; index &lt; nums.length - 1 - i; index++) {\n            if (nums[index] &gt; nums[index + 1]){\n                swap(nums, index, index + 1);\n            }   \n        }\n    }\n}<\/code><\/pre>\n<p>\u5f53\u5e8f\u5217\u5df2\u7ecf\u6709\u5e8f\u65f6\u4ecd\u4f1a\u8fdb\u884c\u4e0d\u5fc5\u8981\u7684\u6bd4\u8f83\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u6807\u5fd7\u8bb0\u5f55\u662f\u5426\u6709\u5143\u7d20\u4ea4\u6362\uff0c\u5982\u679c\u6ca1\u6709\u76f4\u63a5\u7ed3\u675f\u6bd4\u8f83\u3002<\/p>\n<pre><code>public void betterBubbleSort(int[] nums) {\n    boolean swap;\n    for (int i = 0; i &lt; nums.length - 1; i++) {\n        swap = true;\n        for (int index = 0; index &lt; nums.length - 1 - i; index++) {\n            if (nums[index] &gt; nums[index + 1]) {\n                swap(nums, index ,index + 1);\n                swap = false;\n            }\n        }\n        if (swap) break;\n    }\n}<\/code><\/pre>\n<p><strong>\u52a8\u56fe\u6f14\u793a<\/strong><br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Bubble-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4><strong>\u9009\u62e9\u6392\u5e8f(Selection Sort)\u7684\u539f\u7406<\/strong><\/h4>\n<p>\u6bcf\u6b21\u5728\u672a\u6392\u5e8f\u5e8f\u5217\u4e2d\u627e\u5230\u6700\u5c0f\u5143\u7d20\uff0c\u548c\u672a\u6392\u5e8f\u5e8f\u5217\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u4ea4\u6362\u4f4d\u7f6e\uff0c\u518d\u5728\u5269\u4f59\u672a\u6392\u5e8f\u5e8f\u5217\u4e2d\u91cd\u590d\u8be5\u64cd\u4f5c\u76f4\u5230\u6240\u6709\u5143\u7d20\u6392\u5e8f\u5b8c\u6bd5\u3002<\/p>\n<pre><code>public void selectSort(int[] nums) {\n    int minIndex;\n    for (int index = 0; index &lt; nums.length - 1; index++){\n        minIndex = index;\n        for (int i = index + 1;i &lt; nums.length; i++){\n            if(nums[i] &lt; nums[minIndex])\n                minIndex = i;\n        }\n        if (index != minIndex){\n            swap(nums, index, minIndex);\n        }\n    }\n}<\/code><\/pre>\n<p><strong>\u52a8\u56fe\u6f14\u793a<\/strong><br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Selection-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4><strong>\u63d2\u5165\u6392\u5e8f(Insertion Sort)\u7684\u539f\u7406<\/strong><\/h4>\n<p>\u6bcf\u4e00\u8d9f\u5c06\u4e00\u4e2a\u5f85\u6392\u5e8f\u8bb0\u5f55\u6309\u5176\u5173\u952e\u5b57\u7684\u5927\u5c0f\u63d2\u5165\u5230\u5df2\u6392\u597d\u5e8f\u7684\u4e00\u7ec4\u8bb0\u5f55\u7684\u9002\u5f53\u4f4d\u7f6e\u4e0a\uff0c\u76f4\u5230\u6240\u6709\u5f85\u6392\u5e8f\u8bb0\u5f55\u5168\u90e8\u63d2\u5165\u4e3a\u6b62\u3002<\/p>\n<pre><code>public void insertionSort(int[] nums) {\n    for (int i = 1; i &lt; nums.length; i++) {\n        int insertNum = nums[i];\n        int insertIndex;\n        for (insertIndex = i - 1; insertIndex &gt;= 0 &amp;&amp; nums[insertIndex] &gt; insertNum; insertIndex--) {\n            nums[insertIndex + 1] = nums[insertIndex];\n        }\n        nums[insertIndex + 1] = insertNum;\n    }\n}<\/code><\/pre>\n<p>\u76f4\u63a5\u63d2\u5165\u6ca1\u6709\u5229\u7528\u5230\u8981\u63d2\u5165\u7684\u5e8f\u5217\u5df2\u6709\u5e8f\u7684\u7279\u70b9\uff0c\u63d2\u5165\u7b2c i \u4e2a\u5143\u7d20\u65f6\u53ef\u4ee5\u901a\u8fc7\u4e8c\u5206\u67e5\u627e\u627e\u5230\u63d2\u5165\u4f4d\u7f6e insertIndex\uff0c\u518d\u628a i~insertIndex \u4e4b\u95f4\u7684\u6240\u6709\u5143\u7d20\u540e\u79fb\u4e00\u4f4d\uff0c\u628a\u7b2c i \u4e2a\u5143\u7d20\u653e\u5728\u63d2\u5165\u4f4d\u7f6e\u4e0a\u3002<\/p>\n<pre><code>public void binaryInsertionSort(int[] nums) {\n    for (int i = 1; i &lt; nums.length; i++) {\n        int insertNum = nums[i];\n        int insertIndex = -1;\n        int start = 0;\n        int end = i - 1;\n        while (start &lt;= end) {\n            int mid = start + (end - start) \/ 2;\n            if (insertNum &gt; nums[mid])\n                start = mid + 1;\n            else if (insertNum &lt; nums[mid])\n                end = mid - 1;\n            else {\n                insertIndex = mid + 1;\n                break;\n            }\n        }\n        if (insertIndex == -1)\n            insertIndex = start;\n        if (i - insertIndex &gt;= 0)\n            System.arraycopy(nums, insertIndex, nums, insertIndex + 1, i - insertIndex);\n        nums[insertIndex] = insertNum;\n    }\n}<\/code><\/pre>\n<p><strong>\u52a8\u56fe\u6f14\u793a<\/strong><br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Insertion-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4><strong>\u5e0c\u5c14\u6392\u5e8f(Shell Sort)\u7684\u539f\u7406<\/strong><\/h4>\n<p>\u53c8\u79f0\u7f29\u5c0f\u589e\u91cf\u6392\u5e8f\uff0c\u662f\u5bf9\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u7684\u6539\u8fdb\uff0c\u628a\u8bb0\u5f55\u6309\u4e0b\u6807\u7684\u4e00\u5b9a\u589e\u91cf\u5206\u7ec4\uff0c\u5bf9\u6bcf\u7ec4\u8fdb\u884c\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\uff0c\u6bcf\u6b21\u6392\u5e8f\u540e\u51cf\u5c0f\u589e\u91cf\uff0c\u5f53\u589e\u91cf\u51cf\u81f3 1 \u65f6\u6392\u5e8f\u5b8c\u6bd5\u3002<\/p>\n<pre><code>public void shellSort(int[] nums) {\n    for (int d = nums.length \/ 2; d &gt; 0 ; d \/= 2) {\n        for (int i = d; i &lt; nums.length; i++) {\n            int insertNum = nums[i];\n            int insertIndex;\n            for (insertIndex = i - d; insertIndex &gt;= 0 &amp;&amp; nums[insertIndex] &gt; insertNum; insertIndex -= d) {\n                nums[insertIndex + d] = nums[insertIndex];\n            }\n            nums[insertIndex + d] = insertNum;\n        }\n    }\n}<\/code><\/pre>\n<p><strong>\u52a8\u56fe\u6f14\u793a<\/strong><br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Shell-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4><strong>\u5f52\u5e76\u6392\u5e8f(Merge Sort)\u7684\u539f\u7406<\/strong><\/h4>\n<p>\u5f52\u5e76\u6392\u5e8f\u57fa\u4e8e\u5f52\u5e76\u64cd\u4f5c\uff0c\u662f\u4e00\u79cd\u7a33\u5b9a\u7684\u6392\u5e8f\u7b97\u6cd5\u3002<\/p>\n<p><strong>\u57fa\u672c\u539f\u7406\uff1a<\/strong>\u5e94\u7528\u5206\u6cbb\u6cd5\u5c06\u5f85\u6392\u5e8f\u5e8f\u5217\u5206\u6210\u4e24\u90e8\u5206\uff0c\u7136\u540e\u5bf9\u4e24\u90e8\u5206\u5206\u522b\u9012\u5f52\u6392\u5e8f\uff0c\u6700\u540e\u8fdb\u884c\u5408\u5e76\uff0c\u4f7f\u7528\u4e00\u4e2a\u8f85\u52a9\u7a7a\u95f4\u5e76\u8bbe\u5b9a\u4e24\u4e2a\u6307\u9488\u5206\u522b\u6307\u5411\u4e24\u4e2a\u6709\u5e8f\u5e8f\u5217\u7684\u8d77\u59cb\u5143\u7d20\uff0c\u5c06\u6307\u9488\u5bf9\u5e94\u7684\u8f83\u5c0f\u5143\u7d20\u6dfb\u52a0\u5230\u8f85\u52a9\u7a7a\u95f4\uff0c\u91cd\u590d\u8be5\u6b65\u9aa4\u5230\u67d0\u4e00\u5e8f\u5217\u5230\u8fbe\u672b\u5c3e\uff0c\u7136\u540e\u5c06\u53e6\u4e00\u5e8f\u5217\u5269\u4f59\u5143\u7d20\u5408\u5e76\u5230\u8f85\u52a9\u7a7a\u95f4\u672b\u5c3e\u3002<\/p>\n<p><strong>\u9002\u7528\u573a\u666f\uff1a<\/strong>\u6570\u636e\u91cf\u5927\u4e14\u5bf9\u7a33\u5b9a\u6027\u6709\u8981\u6c42\u7684\u60c5\u51b5\u3002<\/p>\n<pre><code> public void mergeSort(int[] arr) {\n    int[] help = new int[arr.length];\n    sort(arr, 0, arr.length - 1);\n}\n\npublic void sort(int[] arr, int start, int end) {\n    if (start == end) return;\n    int mid = start + (end - start) \/ 2;\n    sort(arr, start, mid);\n    sort(arr, mid + 1, end);\n    merge(arr, start, mid, end);\n}\n\npublic void merge(int[] arr, int start, int mid, int end) {\n    if (end + 1 - start &gt;= 0) System.arraycopy(arr, start, help, start, end + 1 - start);\n    int p = start;\n    int q = mid + 1;\n    int index = start;\n    while (p &lt;= mid &amp;&amp; q &lt;= end) {\n        if (help[p] &lt; help[q])\n            arr[index++] = help[p++];\n        else\n            arr[index++] = help[q++];\n    }\n    while (p &lt;= mid) arr[index++] = help[p++];\n    while (q &lt;= end) arr[index++] = help[q++];\n}<\/code><\/pre>\n<p><strong>\u52a8\u56fe\u6f14\u793a<\/strong><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Merge-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4>\u5feb\u901f\u6392\u5e8f(Quick Sort)\u7684\u539f\u7406<\/h4>\n<p>\u662f\u5bf9\u5192\u6ce1\u6392\u5e8f\u7684\u4e00\u79cd\u6539\u8fdb\uff0c\u4e0d\u7a33\u5b9a\uff0c\u5e73\u5747\/\u6700\u597d\u65f6\u95f4\u590d\u6742\u5ea6 O(nlogn)\uff0c\u5143\u7d20\u57fa\u672c\u6709\u5e8f\u65f6\u6700\u574f\u65f6\u95f4\u590d\u6742\u5ea6 O(n\u00b2)\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6 O(logn)\u3002<\/p>\n<p>\u9996\u5148\u9009\u62e9\u4e00\u4e2a\u57fa\u51c6\u5143\u7d20\uff0c\u901a\u8fc7\u4e00\u8d9f\u6392\u5e8f\u5c06\u8981\u6392\u5e8f\u7684\u6570\u636e\u5206\u5272\u6210\u72ec\u7acb\u7684\u4e24\u90e8\u5206\uff0c\u4e00\u90e8\u5206\u5168\u90e8\u5c0f\u4e8e\u7b49\u4e8e\u57fa\u51c6\u5143\u7d20\uff0c\u4e00\u90e8\u5206\u5168\u90e8\u5927\u4e8e\u7b49\u4e8e\u57fa\u51c6\u5143\u7d20\uff0c\u518d\u6309\u6b64\u65b9\u6cd5\u9012\u5f52\u5bf9\u8fd9\u4e24\u90e8\u5206\u6570\u636e\u8fdb\u884c\u5feb\u901f\u6392\u5e8f\u3002<\/p>\n<p>\u5feb\u901f\u6392\u5e8f\u7684\u4e00\u6b21\u5212\u5206\u4ece\u4e24\u5934\u4ea4\u66ff\u641c\u7d22\uff0c\u76f4\u5230 low \u548c high \u6307\u9488\u91cd\u5408\uff0c\u4e00\u8d9f\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\uff0c\u6574\u4e2a\u7b97\u6cd5\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e0e\u5212\u5206\u8d9f\u6570\u6709\u5173\u3002<\/p>\n<p>\u6700\u597d\u60c5\u51b5\u662f\u6bcf\u6b21\u5212\u5206\u9009\u62e9\u7684\u4e2d\u95f4\u6570\u6070\u597d\u5c06\u5f53\u524d\u5e8f\u5217\u7b49\u5206\uff0c\u7ecf\u8fc7 log(n) \u8d9f\u5212\u5206\u4fbf\u53ef\u5f97\u5230\u957f\u5ea6\u4e3a 1 \u7684\u5b50\u8868\uff0c\u8fd9\u6837\u65f6\u95f4\u590d\u6742\u5ea6 O(nlogn)\u3002<\/p>\n<p>\u6700\u574f\u60c5\u51b5\u662f\u6bcf\u6b21\u6240\u9009\u4e2d\u95f4\u6570\u662f\u5f53\u524d\u5e8f\u5217\u4e2d\u7684\u6700\u5927\u6216\u6700\u5c0f\u5143\u7d20\uff0c\u8fd9\u4f7f\u6bcf\u6b21\u5212\u5206\u6240\u5f97\u5b50\u8868\u5176\u4e2d\u4e00\u4e2a\u4e3a\u7a7a\u8868 \uff0c\u8fd9\u6837\u957f\u5ea6\u4e3a n \u7684\u6570\u636e\u8868\u9700\u8981 n \u8d9f\u5212\u5206\uff0c\u6574\u4e2a\u6392\u5e8f\u65f6\u95f4\u590d\u6742\u5ea6 O(n\u00b2)\u3002<\/p>\n<pre><code>public void quickSort(int[] nums, int start, int end) {\n    if (start &lt; end) {\n        int pivotIndex = getPivotIndex(nums, start, end);\n        quickSort(nums, start, pivotIndex - 1);\n        quickSort(nums, pivotIndex + 1, end);\n    }\n}\n\npublic int getPivotIndex(int[] nums, int start, int end) {\n    int pivot = nums[start];\n    int low = start;\n    int high = end;\n    while (low &lt; high) {\n        while (low &lt;= high &amp;&amp; nums[low] &lt;= pivot)\n            low++;\n        while (low &lt;= high &amp;&amp; nums[high] &gt; pivot)\n            high--;\n        if (low &lt; high)\n            swap(nums, low, high);\n    }\n    swap(nums, start, high);\n    return high;\n}<\/code><\/pre>\n<p><strong>\u4f18\u5316\uff1a<\/strong>\u5f53\u89c4\u6a21\u8db3\u591f\u5c0f\u65f6\uff0c\u4f8b\u5982 <code>end - start &lt; 10<\/code> \u65f6\uff0c\u91c7\u7528\u76f4\u63a5\u63d2\u5165\u6392\u5e8f\u3002<\/p>\n<p><strong>\u52a8\u56fe\u6f14\u793a<\/strong><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Quick-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4>\u5806\u6392\u5e8f(Heap Sort)\u7684\u539f\u7406<\/h4>\n<p>\u662f\u5bf9\u76f4\u63a5\u9009\u62e9\u6392\u5e8f\u7684\u6539\u8fdb\uff0c\u4e0d\u7a33\u5b9a\uff0c\u65f6\u95f4\u590d\u6742\u5ea6 O(nlogn)\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6 O(1)\u3002<\/p>\n<p>\u5c06\u5f85\u6392\u5e8f\u8bb0\u5f55\u770b\u4f5c\u5b8c\u5168\u4e8c\u53c9\u6811\uff0c\u53ef\u4ee5\u5efa\u7acb\u5927\u6839\u5806\u6216\u5c0f\u6839\u5806\uff0c\u5927\u6839\u5806\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u4e0d\u5c0f\u4e8e\u5b83\u7684\u5b50\u8282\u70b9\u503c\uff0c\u5c0f\u6839\u5806\u4e2d\u6bcf\u4e2a\u8282\u70b9\u7684\u503c\u90fd\u4e0d\u5927\u4e8e\u5b83\u7684\u5b50\u8282\u70b9\u503c\u3002<\/p>\n<p>\u4ee5\u5927\u6839\u5806\u4e3a\u4f8b\uff0c\u5728\u5efa\u5806\u65f6\u9996\u5148\u5c06\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u4f5c\u4e3a\u5f53\u524d\u8282\u70b9\uff0c\u5982\u679c\u5f53\u524d\u8282\u70b9\u5b58\u5728\u7236\u8282\u70b9\u4e14\u503c\u5927\u4e8e\u7236\u8282\u70b9\uff0c\u5c31\u5c06\u5f53\u524d\u8282\u70b9\u548c\u7236\u8282\u70b9\u4ea4\u6362\u3002\u5728\u79fb\u9664\u65f6\u9996\u5148\u6682\u5b58\u6839\u8282\u70b9\u7684\u503c\uff0c\u7136\u540e\u7528\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u4ee3\u66ff\u6839\u8282\u70b9\u5e76\u4f5c\u4e3a\u5f53\u524d\u8282\u70b9\uff0c\u5982\u679c\u5f53\u524d\u8282\u70b9\u5b58\u5728\u5b50\u8282\u70b9\u4e14\u503c\u5c0f\u4e8e\u5b50\u8282\u70b9\uff0c\u5c31\u5c06\u5176\u4e0e\u503c\u8f83\u5927\u7684\u5b50\u8282\u70b9\u8fdb\u884c\u4ea4\u6362\uff0c\u8c03\u6574\u5b8c\u5806\u540e\u8fd4\u56de\u6682\u5b58\u7684\u503c\u3002<\/p>\n<pre><code>public void add(int[] nums, int i, int num){\n    nums[i] = num;\n    int curIndex = i;\n    while (curIndex &gt; 0) {\n        int parentIndex = (curIndex - 1) \/ 2;\n        if (nums[parentIndex] &lt; nums[curIndex])\n            swap(nums, parentIndex, curIndex);\n        else break;\n        curIndex = parentIndex;\n    }\n}\n\npublic int remove(int[] nums, int size){\n    int result = nums[0];\n    nums[0] = nums[size - 1];\n    int curIndex = 0;\n    while (true) {\n        int leftIndex = curIndex * 2 + 1;\n        int rightIndex = curIndex * 2 + 2;\n        if (leftIndex &gt;= size) break;\n        int maxIndex = leftIndex;\n        if (rightIndex &lt; size &amp;&amp; nums[maxIndex] &lt; nums[rightIndex])\n            maxIndex = rightIndex;\n        if (nums[curIndex] &lt; nums[maxIndex])\n            swap(nums, curIndex, maxIndex);\n        else break;\n        curIndex = maxIndex;\n    }\n    return result;\n}<\/code><\/pre>\n<p><strong>\u52a8\u56fe\u6f14\u793a<\/strong><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Heap-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4>\u8ba1\u6570\u6392\u5e8f(Counting Sort)\u7684\u539f\u7406<\/h4>\n<p>\u8ba1\u6570\u6392\u5e8f\u4e0d\u662f\u57fa\u4e8e\u6bd4\u8f83\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u5176\u6838\u5fc3\u5728\u4e8e\u5c06\u8f93\u5165\u7684\u6570\u636e\u503c\u8f6c\u5316\u4e3a\u952e\u5b58\u50a8\u5728\u989d\u5916\u5f00\u8f9f\u7684\u6570\u7ec4\u7a7a\u95f4\u4e2d\u3002 \u4f5c\u4e3a\u4e00\u79cd\u7ebf\u6027\u65f6\u95f4\u590d\u6742\u5ea6\u7684\u6392\u5e8f\uff0c\u8ba1\u6570\u6392\u5e8f\u8981\u6c42\u8f93\u5165\u7684\u6570\u636e\u5fc5\u987b\u662f\u6709\u786e\u5b9a\u8303\u56f4\u7684\u6574\u6570\u3002<\/p>\n<p>\u7b97\u6cd5\u63cf\u8ff0\uff1a<\/p>\n<ul>\n<li>\u627e\u51fa\u5f85\u6392\u5e8f\u7684\u6570\u7ec4\u4e2d\u6700\u5927\u548c\u6700\u5c0f\u7684\u5143\u7d20\uff1b<\/li>\n<li>\u7edf\u8ba1\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u503c\u4e3ai\u7684\u5143\u7d20\u51fa\u73b0\u7684\u6b21\u6570\uff0c\u5b58\u5165\u6570\u7ec4C\u7684\u7b2ci\u9879\uff1b<\/li>\n<li>\u5bf9\u6240\u6709\u7684\u8ba1\u6570\u7d2f\u52a0(\u4eceC\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u6bcf\u4e00\u9879\u548c\u524d\u4e00\u9879\u76f8\u52a0)\uff1b<\/li>\n<li>\u53cd\u5411\u586b\u5145\u76ee\u6807\u6570\u7ec4\uff1a\u5c06\u6bcf\u4e2a\u5143\u7d20i\u653e\u5728\u65b0\u6570\u7ec4\u7684\u7b2cC(i)\u9879\uff0c\u6bcf\u653e\u4e00\u4e2a\u5143\u7d20\u5c31\u5c06C(i)\u51cf\u53bb1\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-Java\">public void countingSort(int[] nums, maxValue) {\n    int[] bucket = new int(maxValue + 1);\n    int sortedIndex = 0;\n    int arrLen = nums.length,\n    int bucketLen = maxValue + 1;\n    for (int i = 0; i &lt; arrLen; i++) {\n        if (!bucket[nums[i]]) {\n            bucket[nums[i]] = 0;\n        }\n        bucket[nums[i]]++;\n    }\n    for (int j = 0; j &lt; bucketLen; j++) {\n        while(bucket[j] &gt; 0) {\n            nums[sortedIndex++] = j;\n            bucket[j]--;\n        }\n    }\n}<\/code><\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Counting-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4>\u6876\u6392\u5e8f(Bucket Sort)\u7684\u539f\u7406<\/h4>\n<p>\u5c06\u5f85\u6392\u5e8f\u6570\u636e\u5206\u914d\u5230\u6709\u9650\u6570\u91cf\u7684\u6876\u91cc\u3002\u6bcf\u4e2a\u6876\u518d\u5355\u72ec\u8fdb\u884c\u5b50\u6392\u5e8f\uff0c\u6700\u540e\u6309\u987a\u5e8f\u5c06\u591a\u4e2a\u6876\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u5408\u5e76\uff0c\u6392\u5e8f\u5b8c\u6210\u3002\u5f53\u5f85\u6392\u5e8f\u7684\u6570\u7ec4\u5185\u7684\u6570\u503c\u662f\u5747\u5300\u5206\u914d\u7684\u65f6\u5019\uff0c\u6876\u6392\u5e8f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n)\u3002<\/p>\n<p>\u7b97\u6cd5\u63cf\u8ff0<\/p>\n<ul>\n<li>\u8bbe\u7f6e\u4e00\u4e2a\u5b9a\u91cf\u7684\u6570\u7ec4\u5f53\u4f5c\u7a7a\u6876\uff1b<\/li>\n<li>\u904d\u5386\u8f93\u5165\u6570\u636e\uff0c\u5e76\u4e14\u628a\u6570\u636e\u4e00\u4e2a\u4e00\u4e2a\u653e\u5230\u5bf9\u5e94\u7684\u6876\u91cc\u53bb\uff1b<\/li>\n<li>\u5bf9\u6bcf\u4e2a\u4e0d\u662f\u7a7a\u7684\u6876\u8fdb\u884c\u6392\u5e8f\uff1b<\/li>\n<li>\u4ece\u4e0d\u662f\u7a7a\u7684\u6876\u91cc\u628a\u6392\u597d\u5e8f\u7684\u6570\u636e\u62fc\u63a5\u8d77\u6765\u3002 <\/li>\n<\/ul>\n<pre><code class=\"language-JAVA\"> public static void bucketSort(int[] arr){\n     \/\/\u6700\u5927\u6700\u5c0f\u503c\n     int max = arr[0];\n     int min = arr[0];\n     int length = arr.length;\n     for(int i=1; i&lt;length; i++) {\n         if(arr[i] &gt; max) {\n             max = arr[i];\n         } else if(arr[i] &lt; min) {\n             min = arr[i];\n         }\n     }\n     \/\/\u6700\u5927\u503c\u548c\u6700\u5c0f\u503c\u7684\u5dee\n     int diff = max - min;\n     \/\/\u6876\u5217\u8868\n     ArrayList&lt;ArrayList&lt;Integer&gt;&gt; bucketList = new ArrayList&lt;&gt;();\n     for(int i = 0; i &lt; length; i++){\n         bucketList.add(new ArrayList&lt;&gt;());\n     }\n     \/\/\u6bcf\u4e2a\u6876\u7684\u5b58\u6570\u533a\u95f4\n     float section = (float) diff \/ (float) (length - 1);\n     \/\/\u6570\u636e\u5165\u6876\n     for(int i = 0; i &lt; length; i++){\n         \/\/\u5f53\u524d\u6570\u9664\u4ee5\u533a\u95f4\u5f97\u51fa\u5b58\u653e\u6876\u7684\u4f4d\u7f6e \u51cf1\u540e\u5f97\u51fa\u6876\u7684\u4e0b\u6807\n         int num = (int) (arr[i] \/ section) - 1;\n         if(num &lt; 0){\n             num = 0;\n         }\n         bucketList.get(num).add(arr[i]);\n     }\n     \/\/\u6876\u5185\u6392\u5e8f\n     for(int i = 0; i &lt; bucketList.size(); i++){\n         \/\/jdk\u7684\u6392\u5e8f\u901f\u5ea6\u5f53\u7136\u4fe1\u5f97\u8fc7\n         Collections.sort(bucketList.get(i));\n     }\n     \/\/\u5199\u5165\u539f\u6570\u7ec4\n     int index = 0;\n     for(ArrayList&lt;Integer&gt; arrayList : bucketList){\n         for(int value : arrayList){\n             arr[index] = value;\n             index++;\n         }\n     }\n }<\/code><\/pre>\n<p><strong>\u52a8\u56fe\u6f14\u793a<\/strong><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Bucket-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4>\u57fa\u6570\u6392\u5e8f(Radix Sort)\u7684\u539f\u7406<\/h4>\n<p>\u57fa\u6570\u6392\u5e8f\u662f\u6309\u7167\u4f4e\u4f4d\u5148\u6392\u5e8f\uff0c\u7136\u540e\u6536\u96c6\uff1b\u518d\u6309\u7167\u9ad8\u4f4d\u6392\u5e8f\uff0c\u7136\u540e\u518d\u6536\u96c6\uff1b\u4f9d\u6b21\u7c7b\u63a8\uff0c\u76f4\u5230\u6700\u9ad8\u4f4d\u3002\u6709\u65f6\u5019\u6709\u4e9b\u5c5e\u6027\u662f\u6709\u4f18\u5148\u7ea7\u987a\u5e8f\u7684\uff0c\u5148\u6309\u4f4e\u4f18\u5148\u7ea7\u6392\u5e8f\uff0c\u518d\u6309\u9ad8\u4f18\u5148\u7ea7\u6392\u5e8f\u3002\u6700\u540e\u7684\u6b21\u5e8f\u5c31\u662f\u9ad8\u4f18\u5148\u7ea7\u9ad8\u7684\u5728\u524d\uff0c\u9ad8\u4f18\u5148\u7ea7\u76f8\u540c\u7684\u4f4e\u4f18\u5148\u7ea7\u9ad8\u7684\u5728\u524d\u3002<\/p>\n<p>\u7b97\u6cd5\u63cf\u8ff0<\/p>\n<ul>\n<li>\u53d6\u5f97\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u6570\uff0c\u5e76\u53d6\u5f97\u4f4d\u6570\uff1b<\/li>\n<li>array\u4e3a\u539f\u59cb\u6570\u7ec4\uff0c\u4ece\u6700\u4f4e\u4f4d\u5f00\u59cb\u53d6\u6bcf\u4e2a\u4f4d\u7ec4\u6210radix\u6570\u7ec4\uff1b<\/li>\n<li>\u5bf9radix\u8fdb\u884c\u8ba1\u6570\u6392\u5e8f(\u5229\u7528\u8ba1\u6570\u6392\u5e8f\u9002\u7528\u4e8e\u5c0f\u8303\u56f4\u6570\u7684\u7279\u70b9)\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-Java\">public class RadixSort {\n    public static int[] sort(int[] array,int maxDigit){\n        int[] result = new int[array.length];\n        \/\/\u5b83\u7684\u6bcf\u4e00\u4f4d\u7684\u8303\u56f4\uff0c0-9\n        int[] count = new int[10];\n        for(int i=0;i&lt;maxDigit;i++){\n            int division = (int)Math.pow(10,i);\n            for(int n=0;n&lt;array.length;n++){\n                \/\/\u6c42\u6bcf\u4e00\u4f4d\u7684\u6570\u503c\uff0c\u8fdb\u884c\u6c42\u4f59\n                int num = array[n]\/division%10;\n                \/\/\u5c06\u8fd9\u4e2a\u6bcf\u4e00\u4f4d\u7684\u6570\u503c\u4f5c\u4e3acount\u7684\u4e0b\u6807\uff0c\u518d\u8ba1\u7b97\u5176\u51fa\u73b0\u591a\u5c11\u6b21\n                count[num]++;\n            }   \n            \/\/\u8fdb\u884c\u7d2f\u52a0\uff0c\u4ece\u4e0b\u6807\u503c\u4e3a1\u5f00\u59cb\u8fdb\u884c\u7d2f\u52a0\n            for(int m=1;m&lt;count.length;m++){\n                count[m] = count[m] + count[m-1];\n            }   \n            \/\/\u5c06\u539f\u6765\u7684\u6570\u7ec4\u8fdb\u884c\u5012\u53d9\uff0c\u901a\u8fc7\u7d2f\u52a0\u540e\u7684count\u6570\u7ec4\uff0c\n            \/\/\u83b7\u53d6count\u6570\u7ec4\u6bcf\u4e2a\u4e0b\u6807\u6240\u5bf9\u5e94\u7684\u503c\u5c31\u662f\u4e0b\u6807\u7684\u6700\u540e\u4e00\u4e2a\u4e0b\u6807\u51fa\u73b0\u5728result\u7684\u4f4d\u7f6e\u51cf\u4e00\uff0c\n            \/\/\u7136\u540e\u8fdb\u884c\u9012\u51cf\uff0c\u8fd9\u6837\u505a\u662f\u7a33\u5b9a\u7684\uff0c\u6700\u540e\u5f97\u5230\u7684\u6570\u7ec4\u7684\u6309\u987a\u5e8f\u6392\u5217\u7684\n            for(int j=array.length-1;j&gt;=0;j--){\n                int num = array[j]\/division%10;\n                result[--count[num]] = array[j];\n            }       \n            \/\/\u5c06array\u7684\u6570\u7ec4\u91cc\u9762\u7684\u503c\u590d\u5236\u4e3a\u4e86result\n            System.arraycopy(result, 0, array, 0, array.length);\n            \/\/\u586b\u5145count\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f0,\u6e05\u7a7a\u503c\n            Arrays.fill(count,0);\n        }   \n        return result;\n    }\n    \/\/\u83b7\u53d6\u6700\u9ad8\u7684\u4f4d\u6570\n    public static int getMaxDigit(int[] array){\n        int num=0;\n        \/\/\u83b7\u53d6\u6570\u7ec4\u4e2d\u6700\u5927\u7684\u503c\n        int maxValue = Arrays.stream(array).max().getAsInt();\n        \/\/\u83b7\u53d6\u5b83\u7684\u4f4d\u6570\n        while(maxValue!=0){\n            maxValue\/=10;\n            num++;\n        }\n        return num;\n    }\n    public static void main(String[] args) {\n        int[] array = {312,236,187,330,222,457,113};\n        int[] result = sort(array,getMaxDigit(array));\n        System.out.println(Arrays.toString(result));\n    }\n}<\/code><\/pre>\n<p><strong>\u52a8\u56fe\u6f14\u793a<\/strong><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2022\/02\/07\/Radix-Sort.gif\" alt=\"sort-comparison.png\" \/><\/p>\n<h4>\u6392\u5e8f\u7b97\u6cd5\u600e\u4e48\u9009\u62e9<\/h4>\n<p>\u6570\u636e\u91cf\u89c4\u6a21\u8f83\u5c0f\uff0c\u8003\u8651\u76f4\u63a5\u63d2\u5165\u6216\u76f4\u63a5\u9009\u62e9\u3002\u5f53\u5143\u7d20\u5206\u5e03\u6709\u5e8f\u65f6\u76f4\u63a5\u63d2\u5165\u5c06\u5927\u5927\u51cf\u5c11\u6bd4\u8f83\u548c\u79fb\u52a8\u8bb0\u5f55\u7684\u6b21\u6570\uff0c\u5982\u679c\u4e0d\u8981\u6c42\u7a33\u5b9a\u6027\uff0c\u53ef\u4ee5\u4f7f\u7528\u76f4\u63a5\u9009\u62e9\uff0c\u6548\u7387\u7565\u9ad8\u4e8e\u76f4\u63a5\u63d2\u5165\u3002<\/p>\n<p>\u6570\u636e\u91cf\u89c4\u6a21\u4e2d\u7b49\uff0c\u9009\u62e9\u5e0c\u5c14\u6392\u5e8f\u3002<\/p>\n<p>\u6570\u636e\u91cf\u89c4\u6a21\u8f83\u5927\uff0c\u8003\u8651\u5806\u6392\u5e8f(\u5143\u7d20\u5206\u5e03\u63a5\u8fd1\u6b63\u5e8f\u6216\u9006\u5e8f)\u3001\u5feb\u901f\u6392\u5e8f(\u5143\u7d20\u5206\u5e03\u968f\u673a)\u548c\u5f52\u5e76\u6392\u5e8f(\u7a33\u5b9a\u6027)\u3002<\/p>\n<p>\u4e00\u822c\u4e0d\u4f7f\u7528\u5192\u6ce1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5404\u79cd\u7ecf\u5178\u6392\u5e8f\u7b97\u6cd5\u8be6\u89e3 \u2460\u6392\u5e8f\u7684\u5206\u7c7b \u6309\u7167\u5b58\u50a8\u4ecb\u8d28\u6765\u5206\uff0c\u53ef\u4ee5\u5206\u4e3a\u5185\u90e8\u6392\u5e8f\u548c\u5916\u90e8\u6392\u5e8f\u3002 \u5185\u90e8\u6392\u5e8f\uff1a\u6570\u636e\u4e00\u76f4\u5728\u5185\u5b58\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,19],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-7","category-19"],"_links":{"self":[{"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=154"}],"version-history":[{"count":2,"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":518,"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions\/518"}],"wp:attachment":[{"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.huerpu.cc:7000\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}