{"id":39,"date":"2006-11-15T11:59:31","date_gmt":"2006-11-15T03:59:31","guid":{"rendered":"http:\/\/www.mdrink.cn\/mxx\/?p=51"},"modified":"2006-11-15T11:59:31","modified_gmt":"2006-11-15T03:59:31","slug":"qsort%e5%bf%ab%e6%8e%92","status":"publish","type":"post","link":"http:\/\/maxiaoxuan.com\/?p=39","title":{"rendered":"qsort(\u5feb\u6392)"},"content":{"rendered":"<p class=\"cnt\"><span style=\"color: #333399\">\u867d\u7136\u5f88\u65e9\u5c31\u4f1a\u4f7f\u7528qosrt\u4e86\uff0c\u5728\u4f7f\u7528\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u6ca1\u6709\u4efb\u4f55\u95ee\u9898\uff0c\u4eca\u5929\u53d1\u73b0\u8fd8\u662f\u6709\u5f88\u5927\u95ee\u9898\u7684\uff0c\u5728\u8fd9\u91cc\u96c6\u4e2d\u8bf4\u4e00\u4e0b<\/span><\/p>\n<p><span style=\"color: #0000ff\">1.\u6700\u539f\u59cb\u7684\u4ee3\u7801:<\/span><\/p>\n<p><span style=\"color: #99cc00\">procedure quicksort(var b:arr; s,t:integer);<\/span><\/p>\n<p><span style=\"color: #99cc00\">var i,j,x,t1:integer;<\/span><\/p>\n<p><span style=\"color: #99cc00\">begin<\/span><\/p>\n<p><span style=\"color: #99cc00\">i:=s;j:=t;x:=b[i];<\/span><\/p>\n<p><span style=\"color: #99cc00\">repeat<\/span><\/p>\n<p><span style=\"color: #99cc00\">while (b[j]&gt;=x) and (j&gt;i) do j:=j-1;<\/span><\/p>\n<p><span style=\"color: #99cc00\">if j&gt;i then begin t1:=b[i]; b[i]:=b[j];b[j]:=t1;end;<\/span><\/p>\n<p><span style=\"color: #99cc00\">while (b[i]&lt;=x) and (i&lt;j) do i:=i+1;<\/span><\/p>\n<p><span style=\"color: #99cc00\">if i&lt;j then begin t1:=b[j];b[j]:=b[i];b[i]:=t1; end<\/span><\/p>\n<p><span style=\"color: #99cc00\">until i=j;<\/span><\/p>\n<p><span style=\"color: #99cc00\">b[i]:=x;<\/span><\/p>\n<p><span style=\"color: #99cc00\">i:=i+1;j:=j-1;<\/span><\/p>\n<p><span style=\"color: #99cc00\">if s&lt;j then quicksort(b,s,j);<\/span><\/p>\n<p><span style=\"color: #99cc00\">if i&lt;t then quicksort(b,i,t);<\/span><\/p>\n<p><span style=\"color: #99cc00\">end;<\/span><\/p>\n<p><span style=\"background-color: #ffffff;color: #800000\"><strong>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/strong><\/span><\/p>\n<p><span style=\"color: #0000ff\">2.\u6211\u7ecf\u5e38\u4f7f\u7528\u7684\u4ee3\u7801:<\/span><\/p>\n<p><span style=\"color: #339966\">procedure qsort(s,t:longint);<\/span><\/p>\n<p><span style=\"color: #339966\">var i,j,x:longint;<\/span><\/p>\n<p><span style=\"color: #339966\">begin<\/span><\/p>\n<p><span style=\"color: #339966\">i:=s;j:=t;x:=a[i];<\/span><\/p>\n<p><span style=\"color: #339966\">repeat<\/span><\/p>\n<p><span style=\"color: #339966\">while (i&lt;j)and(x&lt;=a[j])do dec(j);<\/span><\/p>\n<p><span style=\"color: #339966\">if i&lt;j then begin<\/span><\/p>\n<p><span style=\"color: #339966\">a[i]:=a[j];<\/span><\/p>\n<p><span style=\"color: #339966\">inc(i);<\/span><\/p>\n<p><span style=\"color: #339966\">end;<\/span><\/p>\n<p><span style=\"color: #339966\">while (i&lt;j)and(a[i]&lt;=x)do inc(i);<\/span><\/p>\n<p><span style=\"color: #339966\">if i&lt;j then begin<\/span><\/p>\n<p><span style=\"color: #339966\">a[j]:=a[i];<\/span><\/p>\n<p><span style=\"color: #339966\">dec(j);<\/span><\/p>\n<p><span style=\"color: #339966\">end;<\/span><\/p>\n<p><span style=\"color: #339966\">until i=j;<\/span><\/p>\n<p><span style=\"color: #339966\">a[i]:=x;<\/span><\/p>\n<p><span style=\"color: #339966\">if s&lt;i-1 then qsort(s,t-1);<\/span><\/p>\n<p><span style=\"color: #339966\">if i+1&lt;t then qsort(i+1,t);<\/span><\/p>\n<p><span style=\"color: #339966\">end;<\/span><\/p>\n<p><span style=\"color: #800000\"><span style=\"background-color: #ffffff\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/span><\/span><\/p>\n<p><span style=\"color: #0000ff\">3.\u8fd9\u4e2a\u662f\u4eca\u5929lccycc\u7ed9\u6211\u7684qsort\u4ee3\u7801\uff0c\u76f8\u5f53\u5feb\u4e86,\u6b63\u5e38\u53ef\u4ee5\u8fc750W\u7684\u6570\u636e,\u800c\u4e14\u6211\u4e5f\u8fc7\u4e86,\u4f46\u662f\u518d\u6d4b\u5c31\u4e0d\u597d\u4f7f\u4e86,30W\u8fc7\u7684\u6bd4\u8f83\u8f7b\u677e!<\/span><\/p>\n<p><span style=\"color: #0000ff\"> \u800c\u4e14\u636e\u6211\u89c2\u5bdf\u6bd4<span style=\"color: #ff0000\">C++<\/span>\u7684qsort\u5feb,\u6bd4STL\u7684sort\u8fd8\u5feb,\u4f30\u8ba1\u662f<span style=\"color: #ff0000\">C++<\/span>\u6587\u4ef6\u64cd\u5360\u7528\u7684\u6bd4\u8f83\u591a\u4f5c\u770b\u6765<span style=\"color: #ff0000\">pascal<\/span>\u4e5f\u4e0d\u4e00\u5b9a\u4ec0\u4e48\u90fd\u6bd4<span style=\"color: #ff0000\">C<\/span>\u5dee,^_^<\/span><\/p>\n<p><span style=\"color: #008080\">procedure sqort(l,h:longint);<\/span><\/p>\n<p><span style=\"color: #008080\">var i,j,k,code:longint;<\/span><\/p>\n<p><span style=\"color: #008080\">begin<\/span><\/p>\n<p><span style=\"color: #008080\">i:=l;j:=h;k:=a[(l+h) div 2];<\/span><\/p>\n<p><span style=\"color: #008080\">while I&lt;j do<\/span><\/p>\n<p><span style=\"color: #008080\">begin<\/span><\/p>\n<p><span style=\"color: #008080\">while a[i]&lt;k do inc(i);<\/span><\/p>\n<p><span style=\"color: #008080\">while a[j]&gt;k do dec(j);<\/span><\/p>\n<p><span style=\"color: #008080\">if i&lt;=j then<\/span><\/p>\n<p><span style=\"color: #008080\">begin<\/span><\/p>\n<p><span style=\"color: #008080\">code:=a[i];a[i]:=a[j];a[j]:=code;<\/span><\/p>\n<p><span style=\"color: #008080\">inc(i);dec(j);<\/span><\/p>\n<p><span style=\"color: #008080\">end;<\/span><\/p>\n<p><span style=\"color: #008080\">end;<\/span><\/p>\n<p><span style=\"color: #008080\">if i&lt;h then sqort(i,h);<\/span><\/p>\n<p><span style=\"color: #008080\">if j&gt;l then sqort(l,j);<\/span><\/p>\n<p><span style=\"color: #008080\">end;<\/span><\/p>\n<p><span style=\"color: #808080\">\u539f\u6765\u4e00\u4e2a\u7b80\u5355\u7684\u5feb\u6392\u6709\u8fd9\u4e48\u5927\u7684\u533a\u522b\uff0c\u7a0b\u5e8f\u662f\u5426\u5783\u573e\u4e5f\u5176\u4e86\u5f88\u5927\u5f71\u54cd\uff0c\u4f46\u662f\u7f16\u7a0b\u6c34\u5e73\u4e0d\u662f\u4e00\u671d\u4e00\u5915\u5c31\u53ef\u4ee5\u6210\u5c31\u7684\uff0c\u4ee5\u540e\u8981\u6ce8\u610f!!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u867d\u7136\u5f88\u65e9\u5c31\u4f1a\u4f7f\u7528qosrt\u4e86\uff0c\u5728\u4f7f\u7528\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u6ca1\u6709\u4efb\u4f55\u95ee\u9898\uff0c\u4eca\u5929\u53d1\u73b0\u8fd8\u662f\u6709\u5f88\u5927\u95ee\u9898\u7684\uff0c\u5728\u8fd9\u91cc\u96c6\u4e2d\u8bf4\u4e00\u4e0b 1.\u6700 &hellip; <a href=\"http:\/\/maxiaoxuan.com\/?p=39\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">qsort(\u5feb\u6392)<\/span><\/a><\/p>\n","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-39","post","type-post","status-publish","format-standard","hentry","category-computer"],"_links":{"self":[{"href":"http:\/\/maxiaoxuan.com\/index.php?rest_route=\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/maxiaoxuan.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/maxiaoxuan.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/maxiaoxuan.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/maxiaoxuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=39"}],"version-history":[{"count":0,"href":"http:\/\/maxiaoxuan.com\/index.php?rest_route=\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"http:\/\/maxiaoxuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/maxiaoxuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/maxiaoxuan.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}