{"id":46,"date":"2024-11-15T20:07:22","date_gmt":"2024-11-15T12:07:22","guid":{"rendered":"https:\/\/ceshiy.icu\/?p=46"},"modified":"2024-11-15T20:07:22","modified_gmt":"2024-11-15T12:07:22","slug":"%e5%86%92%e6%b3%a1%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/blog.ceshiy.fun\/index.php\/2024\/11\/15\/%e5%86%92%e6%b3%a1%e6%8e%92%e5%ba%8f\/","title":{"rendered":"\u5192\u6ce1\u6392\u5e8f"},"content":{"rendered":"<p class=\"wp-block-paragraph\">\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6O(n),\u6700\u5dee\u4e3aO(n^2)<\/p>\n<pre class=\"wp-block-code\"><code>\/* \u5192\u6ce1\u6392\u5e8f *\/\nvoid bubbleSort(int nums[], int size) {\n    \/\/ \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (int i = size - 1; i &gt; 0; i--) {\n        \/\/ \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\n        for (int j = 0; j &lt; i; j++) {\n            if (nums[j] &gt; nums[j + 1]) {\n                int temp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = temp;\n            }\n        }\n    }\n}<\/code><\/pre>\n<p class=\"wp-block-paragraph\">\u6548\u7387\u4f18\u5316\u540e<\/p>\n<pre class=\"wp-block-code\"><code>\/* \u5192\u6ce1\u6392\u5e8f\uff08\u6807\u5fd7\u4f18\u5316\uff09*\/\nvoid bubbleSortWithFlag(int nums[], int size) {\n    \/\/ \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (int i = size - 1; i &gt; 0; i--) {\n        bool flag = false;\n        \/\/ \u5185\u5faa\u73af\uff1a\u5c06\u672a\u6392\u5e8f\u533a\u95f4 [0, i] \u4e2d\u7684\u6700\u5927\u5143\u7d20\u4ea4\u6362\u81f3\u8be5\u533a\u95f4\u7684\u6700\u53f3\u7aef\n        for (int j = 0; j &lt; i; j++) {\n            if (nums[j] &gt; nums[j + 1]) {\n                int temp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = temp;\n                flag = true;\n            }\n        }\n        if (!flag)\n            break;\n    }\n}<\/code><\/pre>\n<p class=\"wp-block-paragraph\"><\/p>","protected":false},"excerpt":{"rendered":"<p>\u6700\u4f73\u65f6\u95f4\u590d\u6742\u5ea6O(n),\u6700\u5dee\u4e3aO(n^2) \u6548\u7387\u4f18\u5316\u540e<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-paixusuanfa"],"_links":{"self":[{"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":1,"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":47,"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/posts\/46\/revisions\/47"}],"wp:attachment":[{"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ceshiy.fun\/index.php\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}