{"id":39865,"date":"2023-12-11T14:49:04","date_gmt":"2023-12-11T06:49:04","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=39865"},"modified":"2023-12-11T14:49:04","modified_gmt":"2023-12-11T06:49:04","slug":"java%e7%89%88%e5%9f%ba%e6%95%b0%e6%8e%92%e5%ba%8f%e7%a8%b3%e5%ae%9a","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/java%e7%89%88%e5%9f%ba%e6%95%b0%e6%8e%92%e5%ba%8f%e7%a8%b3%e5%ae%9a\/","title":{"rendered":"Java\u7248\u57fa\u6570\u6392\u5e8f[\u7a33\u5b9a]"},"content":{"rendered":"<p>&#8220;`&#8221;                    \u539f\u7406\uff1a\u5206\u914d\u52a0\u6536\u96c6<\/p>\n<p>\u590d\u6742\u5ea6\uff1a O(d(n+r)) r\u4e3a\u57fa\u6570d\u4e3a\u4f4d\u6570 \u7a7a\u95f4\u590d\u6742\u5ea6O(n+r)<\/p>\n<p>&lt;pre&gt;&lt;code class=&quot;&quot;language-java&quot;&quot; lang=&quot;&quot;java&quot;&quot;&gt;\/\/ \u57fa\u6570\u6392\u5e8f<br \/>\n    public void radixSort(int[] a, int begin, int end, int digit) {<br \/>\n        \/\/ \u57fa\u6570<br \/>\n        final int radix = 10;<br \/>\n        \/\/ \u6876\u4e2d\u7684\u6570\u636e\u7edf\u8ba1<br \/>\n        int[] count = new int[radix];<br \/>\n        int[] bucket = new int[end-begin+1];<\/p>\n<p>        \/\/ \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u6267\u884c\u6392\u5e8f\u8fc7\u7a0b<br \/>\n        for (int i = 1; i &lt;= digit; i++) {<br \/>\n            \/\/ \u6e05\u7a7a\u6876\u4e2d\u7684\u6570\u636e\u7edf\u8ba1<br \/>\n            for (int j = 0; j &lt; radix; j++) {<br \/>\n                count[j] = 0;<br \/>\n            }<\/p>\n<p>            \/\/ \u7edf\u8ba1\u5404\u4e2a\u6876\u5c06\u8981\u88c5\u5165\u7684\u6570\u636e\u4e2a\u6570<br \/>\n            for (int j = begin; j &lt;= end; j++) {<br \/>\n                int index = getDigit(a[j], i);<br \/>\n                count[index]++;<br \/>\n            }<\/p>\n<p>            \/\/ count[i]\u8868\u793a\u7b2ci\u4e2a\u6876\u7684\u53f3\u8fb9\u754c\u7d22\u5f15<br \/>\n            for (int j = 1; j &lt; radix; j++) {<br \/>\n                count[j] = count[j] + count[j &#8211; 1];<br \/>\n            }<\/p>\n<p>            \/\/ \u5c06\u6570\u636e\u4f9d\u6b21\u88c5\u5165\u6876\u4e2d<br \/>\n            \/\/ \u8fd9\u91cc\u8981\u4ece\u53f3\u5411\u5de6\u626b\u63cf\uff0c\u4fdd\u8bc1\u6392\u5e8f\u7a33\u5b9a\u6027<br \/>\n            for (int j = end; j &gt;= begin; j&#8211;) {<br \/>\n                int index = getDigit(a[j], i);<br \/>\n                bucket[count[index] &#8211; 1] = a[j];<br \/>\n                count[index]&#8211;;<br \/>\n            }<\/p>\n<p>            \/\/ \u53d6\u51fa\uff0c\u6b64\u65f6\u5df2\u662f\u5bf9\u5e94\u5f53\u524d\u4f4d\u6570\u6709\u5e8f\u7684\u8868<br \/>\n            for (int j = 0; j &lt; bucket.length; j++) {<br \/>\n                a[j] = bucket[j];<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/\/ \u83b7\u53d6x\u7684\u7b2cd\u4f4d\u7684\u6570\u5b57\uff0c\u5176\u4e2d\u6700\u4f4e\u4f4dd=1<br \/>\n    private int getDigit(int x, int d) {<br \/>\n        String div = &quot;&quot;1&quot;&quot;;<br \/>\n        while (d &gt;= 2) {<br \/>\n            div += &quot;&quot;0&quot;&quot;;<br \/>\n            d&#8211;;<br \/>\n        }<br \/>\n        return x\/Integer.parseInt(div) % 10;<br \/>\n    }<br \/>\n}<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u539f\u7406\uff1a\u5206\u914d\u52a0\u6536\u96c6 \u590d\u6742\u5ea6\uff1a O(d(n+r)) r\u4e3a\u57fa\u6570d\u4e3a\u4f4d\u6570 \u7a7a\u95f4\u590d\u6742\u5ea6O [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-39865","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/39865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=39865"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/39865\/revisions"}],"predecessor-version":[{"id":39866,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/39865\/revisions\/39866"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=39865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=39865"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=39865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}