{"id":3624,"date":"2023-01-19T16:32:10","date_gmt":"2023-01-19T08:32:10","guid":{"rendered":"https:\/\/qaqaq.top\/?p=3624"},"modified":"2023-01-19T16:32:11","modified_gmt":"2023-01-19T08:32:11","slug":"%e9%b8%a1%e5%b0%be%e9%85%92%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=3624","title":{"rendered":"\u9e21\u5c3e\u9152\u6392\u5e8f"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package chapter4.part2;\r\n\r\nimport java.util.Arrays;\r\n\r\npublic class CockTailSort {\r\n\r\n    public static void sort(int array&#91;])\r\n    {\r\n        int tmp  = 0;\r\n        for(int i=0; i&lt;array.length\/2; i++)\r\n        {\r\n            \/\/\u6709\u5e8f\u6807\u8bb0\uff0c\u6bcf\u4e00\u8f6e\u7684\u521d\u59cb\u662ftrue\r\n            boolean isSorted = true;\r\n            \/\/\u5947\u6570\u8f6e\uff0c\u4ece\u5de6\u5411\u53f3\u6bd4\u8f83\u548c\u4ea4\u6362\r\n            for(int j=i; j&lt;array.length-i-1; j++)\r\n            {\r\n                if(array&#91;j] > array&#91;j+1])\r\n                {\r\n                    tmp = array&#91;j];\r\n                    array&#91;j] = array&#91;j+1];\r\n                    array&#91;j+1] = tmp;\r\n                    \/\/\u6709\u5143\u7d20\u4ea4\u6362\uff0c\u6240\u4ee5\u4e0d\u662f\u6709\u5e8f\uff0c\u6807\u8bb0\u53d8\u4e3afalse\r\n                    isSorted = false;\r\n                }\r\n            }\r\n            if(isSorted){\r\n                break;\r\n            }\r\n\r\n            \/\/\u5076\u6570\u8f6e\u4e4b\u524d\uff0c\u91cd\u65b0\u6807\u8bb0\u4e3atrue\r\n            isSorted = true;\r\n            \/\/\u5076\u6570\u8f6e\uff0c\u4ece\u53f3\u5411\u5de6\u6bd4\u8f83\u548c\u4ea4\u6362\r\n            for(int j=array.length-i-1; j>i; j--)\r\n            {\r\n                if(array&#91;j] &lt; array&#91;j-1])\r\n                {\r\n                    tmp = array&#91;j];\r\n                    array&#91;j] = array&#91;j-1];\r\n                    array&#91;j-1] = tmp;\r\n                    \/\/\u6709\u5143\u7d20\u4ea4\u6362\uff0c\u6240\u4ee5\u4e0d\u662f\u6709\u5e8f\uff0c\u6807\u8bb0\u53d8\u4e3afalse\r\n                    isSorted = false;\r\n                }\r\n            }\r\n            if(isSorted){\r\n                break;\r\n            }\r\n        }\r\n    }\r\n\r\n    public static void main(String&#91;] args){\r\n        int&#91;] array = new int&#91;]{2,3,4,5,6,7,8,1};\r\n        sort(array);\r\n        System.out.println(Arrays.toString(array));\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[133],"class_list":["post-3624","post","type-post","status-publish","format-standard","hentry","category-82","tag-133"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/3624"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3624"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/3624\/revisions"}],"predecessor-version":[{"id":3625,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/3624\/revisions\/3625"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}