{"id":45328,"date":"2023-12-11T15:05:31","date_gmt":"2023-12-11T07:05:31","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=45328"},"modified":"2023-12-11T15:05:31","modified_gmt":"2023-12-11T07:05:31","slug":"%e7%94%a8java%e5%86%99%e4%b8%80%e4%b8%aa%e5%86%92%e6%b3%a1%e6%8e%92%e5%ba%8f%ef%bc%9f-2","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/%e7%94%a8java%e5%86%99%e4%b8%80%e4%b8%aa%e5%86%92%e6%b3%a1%e6%8e%92%e5%ba%8f%ef%bc%9f-2\/","title":{"rendered":"\u7528java\u5199\u4e00\u4e2a\u5192\u6ce1\u6392\u5e8f\uff1f"},"content":{"rendered":"<p>&#8220;`&#8221;                    \u8003\u5bdf\u70b9\uff1a\u5192\u6ce1\u6392\u5e8f<\/p>\n<p>\u00a0<\/p>\n<p>&lt;pre&gt;&lt;code class=&quot;&quot;language-java&quot;&quot; lang=&quot;&quot;java&quot;&quot;&gt;import<br \/>\njava.util.Comparator;<br \/>\n \/**<br \/>\n  * \u6392\u5e8f\u5668\u63a5\u53e3(\u7b56\u7565\u6a21\u5f0f: \u5c06\u7b97\u6cd5\u5c01\u88c5\u5230\u5177\u6709\u5171\u540c\u63a5\u53e3\u7684\u72ec\u7acb\u7684\u7c7b\u4e2d\u4f7f\u5f97\u5b83\u4eec\u53ef\u4ee5\u76f8\u4e92\u66ff\u6362)<br \/>\n  *\/<br \/>\n public interface Sorter {<br \/>\n    \/**<br \/>\n     *<br \/>\n  *\/<br \/>\n public interface Sorter {<br \/>\n    \/**<br \/>\n     * \u6392\u5e8f<br \/>\n     * @param list \u5f85\u6392\u5e8f\u7684\u6570\u7ec4<br \/>\n     *\/<br \/>\n    public &lt;T extends Comparable&lt;T&gt;&gt; void sort(T[] list);<br \/>\n    \/**<br \/>\n     * \u6392\u5e8f<br \/>\n     * @param list \u5f85\u6392\u5e8f\u7684\u6570\u7ec4<br \/>\n     * @param comp \u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684\u6bd4\u8f83\u5668<br \/>\n     *\/<br \/>\n    public &lt;T&gt; void sort(T[] list, Comparator&lt;T&gt; comp);<br \/>\n }<\/p>\n<p> import java.util.Comparator;<\/p>\n<p> \/**<br \/>\n  * \u5192\u6ce1\u6392\u5e8f<br \/>\n  *<br \/>\n  *\/<br \/>\n public class BubbleSorter implements Sorter {<br \/>\n     @Override<br \/>\n     public &lt;T extends Comparable&lt;T&gt;&gt; void sort(T[] list) {<br \/>\n         boolean swapped = true;<br \/>\n         for (int i = 1, len = list.length; i&lt; len &amp;&amp; swapped; ++i) {<br \/>\n             swapped =false;<br \/>\n             for (int j =0; j &lt; len &#8211; i; ++j) {<br \/>\n                    if (list[j].compareTo(list[j + 1]) &gt; 0) {<br \/>\n                    T temp = list[j];<br \/>\n                    list[j] = list[j + 1];<br \/>\n                    list[j + 1] = temp;<br \/>\n                    swapped = true;<br \/>\n                }<br \/>\n             }<br \/>\n         }<br \/>\n     }<\/p>\n<p>     @Override<br \/>\n     public &lt;T&gt; void sort(T[] list, Comparator&lt;T&gt;<br \/>\ncomp) {<br \/>\n         boolean swapped = true;<br \/>\n         for (int i = 1, len = list.length; i&lt; len &amp;&amp; swapped; ++i) {<br \/>\n             swapped =false;<br \/>\n             for (int j =0; j &lt; len &#8211; i; ++j) {<br \/>\n                    if (comp.compare(list[j], list[j + 1]) &gt; 0) {<br \/>\n                    T temp = list[j];<br \/>\n                    list[j] = list[j + 1];<br \/>\n                    list[j + 1] = temp;<br \/>\n                    swapped = true;<br \/>\n                }<br \/>\n             }<br \/>\n         }<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u00a0<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u8003\u5bdf\u70b9\uff1a\u5192\u6ce1\u6392\u5e8f \u00a0 &lt;pre&gt;&lt;code class=&#038;q [&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-45328","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/45328","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=45328"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/45328\/revisions"}],"predecessor-version":[{"id":45329,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/45328\/revisions\/45329"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=45328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=45328"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=45328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}