{"id":51,"date":"2026-03-26T16:02:25","date_gmt":"2026-03-26T08:02:25","guid":{"rendered":"https:\/\/geocommunity.vip\/?p=51"},"modified":"2026-03-31T22:52:19","modified_gmt":"2026-03-31T14:52:19","slug":"%e5%bd%92%e5%b9%b6%e6%8e%92%e5%ba%8f%e5%92%8c%e5%bf%ab%e9%80%9f%e6%8e%92%e5%ba%8f%e7%9a%84%e9%80%92%e5%bd%92%e6%80%9d%e6%83%b3%e4%b8%8eqsort%e7%9a%84%e7%ae%80%e5%8d%95%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/geocommunity.vip\/index.php\/2026\/03\/26\/%e5%bd%92%e5%b9%b6%e6%8e%92%e5%ba%8f%e5%92%8c%e5%bf%ab%e9%80%9f%e6%8e%92%e5%ba%8f%e7%9a%84%e9%80%92%e5%bd%92%e6%80%9d%e6%83%b3%e4%b8%8eqsort%e7%9a%84%e7%ae%80%e5%8d%95%e5%ae%9e%e7%8e%b0\/","title":{"rendered":"\u5f52\u5e76\u6392\u5e8f\u548c\u5feb\u901f\u6392\u5e8f\u7684\u9012\u5f52\u601d\u60f3\u4e0eqsort\u7684\u7b80\u5355\u5b9e\u73b0\uff08B\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4e00\u3001\u5f52\u5e76\u6392\u5e8f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u601d\u60f3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5206\u89e3\uff08Divide\uff09<\/strong>\uff1a\u5c06\u5f53\u524d\u5e8f\u5217\u4ece\u4e2d\u95f4\u4e00\u5206\u4e3a\u4e8c\uff0c\u9012\u5f52\u5730\u5bf9\u5de6\u534a\u90e8\u5206\u548c\u53f3\u534a\u90e8\u5206\u8fdb\u884c\u62c6\u5206\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u51b3\uff08Conquer\uff09<\/strong>\uff1a\u5f53\u62c6\u5206\u5230\u6bcf\u4e2a\u5b50\u5e8f\u5217\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\u65f6\uff0c\u8ba4\u4e3a\u8be5\u5e8f\u5217\u662f\u6709\u5e8f\u7684\uff08<strong>\u9012\u5f52\u7ec8\u6b62\u6761\u4ef6<\/strong>\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5408\u5e76\uff08Combine\uff09<\/strong>\uff1a\u5c06\u4e24\u4e2a\u5df2\u6392\u5e8f\u7684\u5b50\u5e8f\u5217\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7684\u6709\u5e8f\u5e8f\u5217\uff0c\u76f4\u5230\u6700\u7ec8\u5408\u5e76\u4e3a\u539f\u957f\u5ea6\u7684\u6709\u5e8f\u6570\u7ec4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5373\uff0c\u4e0d\u65ad\u8fdb\u884c\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f53\u6700\u540eleft == right\u65f6\uff0c\u9012\u5f52\u7ed3\u675f\uff0c\u5f00\u59cb\u5408\u5e76\uff0c\u5e76\u4e14\u4e0d\u65ad\u4ece\u6df1\u5c42\u8fd4\u56de\u5408\u5e76\u7684\u7ed3\u679c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u7279\u70b9\u548c\u52a3\u52bf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(n log n)\uff1alogn\u662f\u6307\u9012\u5f52\u7684\u5c42\u6b21  n\u662f\u6307\u5408\u5e76\u6392\u5e8f\u4ea7\u751f\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(n)\uff08\u9700\u8981\u4e34\u65f6\u6570\u7ec4\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a33\u5b9a\u6392\u5e8f\uff08\u4f7f\u7528 &lt;= \u4fdd\u8bc1\u76f8\u7b49\u5143\u7d20\u7684\u76f8\u5bf9\u987a\u5e8f\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u7b97\u6cd5\u5b9e\u73b0<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"842\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-12-1024x842.png\" alt=\"\" class=\"wp-image-52\" style=\"width:518px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-12-1024x842.png 1024w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-12-300x247.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-12-768x632.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-12.png 1048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">                                                  \uff08\u9012\u5f52\u4e3b\u51fd\u6570\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9012\u5f52\u4e3b\u51fd\u6570\uff0c\u4e0d\u8981\u601d\u8003\u8fd9\u4e48\u590d\u6742\uff0c\u4ece\u6700\u7b80\u5355\u7684\u5c42\u9762\u601d\u8003\uff0c\u95ee\u9898\u53d8\u5f97\u5f88\u7b80\u5355\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"565\" height=\"1024\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-13-565x1024.png\" alt=\"\" class=\"wp-image-53\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-13-565x1024.png 565w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-13-166x300.png 166w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-13-768x1391.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-13-848x1536.png 848w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-13.png 1126w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">                                                   \uff08\u5f52\u5e76\u51fd\u6570\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6838\u5fc3\u601d\u60f3\u662f\u5f00\u8f9f\u4e24\u4e2a\u4e34\u65f6\u6570\u7ec4\u5b58\u50a8\u5de6\u53f3\u90e8\u5206\uff0c\u5e76\u901a\u8fc7\u53cc\u6307\u9488\u4e0d\u65ad\u6bd4\u8f83\uff0c\u586b\u5145arr\u539f\u6570\u7ec4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e8c\u3001qsort\u7684\u7b80\u5355\u5b9e\u73b0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9488\u5bf9malloc\u5f00\u8f9f\u7684\u6570\u7ec4\u6392\u5e8f\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u4e00\u7ef4\u6570\u7ec4<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1020\" height=\"634\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-14.png\" alt=\"\" class=\"wp-image-55\" style=\"aspect-ratio:1.6088582971719287;width:522px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-14.png 1020w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-14-300x186.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-14-768x477.png 768w\" sizes=\"auto, (max-width: 1020px) 100vw, 1020px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"330\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-15.png\" alt=\"\" class=\"wp-image-56\" style=\"aspect-ratio:2.7637260950030846;width:389px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-15.png 912w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-15-300x109.png 300w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-15-768x278.png 768w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u4e8c\u7ef4\u6570\u7ec4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int cmp(const void *a, const void *b) {\n    int *row1 = (int *)a;\n    int *row2 = (int *)b;\n\n    \/\/ \u7b2c\u4e00\u7ea7\u6392\u5e8f\n    if (row1&#91;0] != row2&#91;0]) {\n        return row1&#91;0] - row2&#91;0];\n    }\n\n    \/\/ \u7b2c\u4e8c\u7ea7\u6392\u5e8f\n    return row1&#91;1] - row2&#91;1];\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\nqsort(arr, N, sizeof(arr&#91;0]), cmp);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e09\u3001\u5feb\u901f\u6392\u5e8f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u601d\u60f3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u4e00\u8d9f\u6392\u5e8f\u5c06\u8981\u6392\u5e8f\u7684\u6570\u636e\u5206\u5272\u6210\u72ec\u7acb\u7684\u4e24\u90e8\u5206\uff0c\u5176\u4e2d\u4e00\u90e8\u5206\u7684\u6240\u6709\u6570\u636e\u90fd\u6bd4\u53e6\u5916\u4e00\u90e8\u5206\u7684\u6240\u6709\u6570\u636e\u90fd\u8981\u5c0f\uff08\u6216\u5c0f\u4e8e\u7b49\u4e8e\uff09\uff0c\u7136\u540e\u518d\u6309\u6b64\u65b9\u6cd5\u5bf9\u8fd9\u4e24\u90e8\u5206\u6570\u636e\u5206\u522b\u8fdb\u884c\u5feb\u901f\u6392\u5e8f\uff0c\u6574\u4e2a\u6392\u5e8f\u8fc7\u7a0b\u53ef\u4ee5\u9012\u5f52\u8fdb\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u7279\u70b9\u548c\u52a3\u52bf<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\uff081\uff09\u5feb\u901f\u6392\u5e8f\u7684\u7279\u70b9\uff08\u4f18\u52bf\uff09<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6781\u9ad8\u7684\u5e73\u5747\u6548\u7387\uff1a<\/strong> \u867d\u7136\u5176\u5e73\u5747\u65f6\u95f4\u590d\u6742\u5ea6\u4e0e\u5f52\u5e76\u6392\u5e8f\u3001\u5806\u6392\u5e8f\u4e00\u6837\u90fd\u662f $O(n \\log n)$\uff0c\u4f46\u5728\u5b9e\u9645\u8fd0\u884c\u4e2d\uff0c\u5feb\u6392\u901a\u5e38\u6bd4\u5b83\u4eec\u5feb\u3002\u8fd9\u662f\u56e0\u4e3a\u5b83\u7684\u5185\u90e8\u5faa\u73af\u6307\u4ee4\u975e\u5e38\u7b80\u5355\uff0c\u4e14\u5bf9 <strong>CPU \u7f13\u5b58\uff08Cache\uff09<\/strong> \u975e\u5e38\u53cb\u597d\u3002<\/li>\n\n\n\n<li><strong>\u539f\u5730\u6392\u5e8f (In-place)\uff1a<\/strong> \u4e0e\u5f52\u5e76\u6392\u5e8f\u9700\u8981 $O(n)$ \u7684\u8f85\u52a9\u6570\u7ec4\u4e0d\u540c\uff0c\u5feb\u6392\u53ea\u9700\u8981 $O(\\log n)$ \u7684\u9012\u5f52\u6808\u7a7a\u95f4\u3002\u5728\u5185\u5b58\u53d7\u9650\u7684\u5d4c\u5165\u5f0f\u7cfb\u7edf\u6216\u5904\u7406\u6d77\u91cf GIS \u7a7a\u95f4\u6570\u636e\u65f6\uff0c\u8fd9\u4e2a\u4f18\u52bf\u975e\u5e38\u5de8\u5927\u3002<\/li>\n\n\n\n<li><strong>\u9ad8\u5ea6\u53ef\u4f18\u5316\uff1a<\/strong> * \u53ef\u4ee5\u901a\u8fc7\u201c\u4e09\u6570\u53d6\u4e2d\u201d\u6216\u201c\u968f\u673a\u57fa\u51c6\u201d\u6765\u89c4\u907f\u6781\u7aef\u7684\u6d4b\u8bd5\u6570\u636e\u3002\n<ul class=\"wp-block-list\">\n<li>\u5f53\u9012\u5f52\u5230\u533a\u95f4\u8f83\u5c0f\uff08\u5982 $n &lt; 15$\uff09\u65f6\uff0c\u53ef\u4ee5\u5207\u6362\u4e3a<strong>\u63d2\u5165\u6392\u5e8f<\/strong>\u6765\u8fdb\u4e00\u6b65\u69a8\u5e72\u6027\u80fd\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\uff082\uff09\u5feb\u901f\u6392\u5e8f\u7684\u52a3\u52bf\uff08\u77ed\u677f\uff09<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e0d\u7a33\u5b9a\u6027 (Unstable)\uff1a<\/strong> \u8fd9\u662f\u5feb\u6392\u6700\u5927\u7684\u786c\u4f24\u3002\u6b63\u5982\u4f60\u89c2\u5bdf\u5230\u7684\uff0c<code>swap<\/code> \u64cd\u4f5c\u4f1a\u6253\u4e71\u76f8\u7b49\u5143\u7d20\u7684\u539f\u59cb\u76f8\u5bf9\u987a\u5e8f\u3002<strong>\u4e3e\u4f8b\uff1a<\/strong> \u5982\u679c\u4f60\u5148\u6309\u201c\u6210\u7ee9\u201d\u6392\u5e8f\uff0c\u518d\u6309\u201c\u5b66\u53f7\u201d\u6392\u5e8f\uff0c\u5feb\u6392\u53ef\u80fd\u4f1a\u628a\u4f60\u4e4b\u524d\u6392\u597d\u7684\u6210\u7ee9\u987a\u5e8f\u641e\u4e71\u3002\u5728 C \u8bed\u8a00\u4e2d\uff0c\u5982\u679c\u4f60\u9700\u8981\u7a33\u5b9a\u6392\u5e8f\uff0c\u901a\u5e38\u5f97\u6539\u7528 <code>mergesort<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u6700\u574f\u60c5\u51b5\u89e6\u53d1\uff1a<\/strong> \u5982\u679c\u57fa\u51c6\u503c\u9009\u5f97\u4e0d\u597d\uff08\u6bd4\u5982\u6bcf\u6b21\u90fd\u9009\u5230\u6700\u5c0f\u6216\u6700\u5927\u7684\u6570\uff09\uff0c\u5206\u533a\u5c31\u4f1a\u6781\u5ea6\u4e0d\u5747\u5300\u3002\n<ul class=\"wp-block-list\">\n<li><strong>\u73b0\u8c61\uff1a<\/strong> \u9012\u5f52\u6811\u9000\u5316\u6210\u4e00\u4e2a\u5355\u5411\u94fe\u8868\u3002<\/li>\n\n\n\n<li><strong>\u540e\u679c\uff1a<\/strong> \u65f6\u95f4\u590d\u6742\u5ea6\u52a3\u5316\u4e3a $O(n^2)$\uff0c\u5e76\u4e14\u6781\u6613\u89e6\u53d1 <strong>\u6808\u6ea2\u51fa (Stack Overflow)<\/strong>\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5bf9\u5c0f\u89c4\u6a21\u6570\u636e\u4e0d\u5212\u7b97\uff1a<\/strong> \u7531\u4e8e\u9012\u5f52\u8c03\u7528\u5b58\u5728\u5f00\u9500\uff0c\u5bf9\u4e8e\u53ea\u6709\u51e0\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u5feb\u6392\u53cd\u800c\u4e0d\u5982\u7b80\u5355\u7684\u63d2\u5165\u6392\u5e8f\u5feb\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u7b97\u6cd5\u5b9e\u73b0<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"1024\" src=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-18-735x1024.png\" alt=\"\" class=\"wp-image-60\" style=\"aspect-ratio:0.717795342875454;width:580px;height:auto\" srcset=\"https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-18-735x1024.png 735w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-18-215x300.png 215w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-18-768x1070.png 768w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-18-1103x1536.png 1103w, https:\/\/geocommunity.vip\/wp-content\/uploads\/2026\/03\/image-18.png 1328w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5f52\u5e76\u6392\u5e8f 1\u3001\u601d\u60f3 \u5206\u89e3\uff08Divide\uff09\uff1a\u5c06\u5f53 &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],"tags":[],"class_list":["post-51","post","type-post","status-publish","format-standard","hentry","category-7"],"_links":{"self":[{"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":5,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"predecessor-version":[{"id":89,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/posts\/51\/revisions\/89"}],"wp:attachment":[{"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geocommunity.vip\/index.php\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}