{"id":44,"date":"2016-10-17T02:04:57","date_gmt":"2016-10-17T02:04:57","guid":{"rendered":"http:\/\/www.haoyuan.info\/?p=44"},"modified":"2016-10-20T03:35:47","modified_gmt":"2016-10-20T03:35:47","slug":"%e5%bf%ab%e9%80%9f%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/haoyuan.info\/?p=44","title":{"rendered":"\u5feb\u901f\u6392\u5e8f"},"content":{"rendered":"<p>[hide][code lang=&#8221;c&#8221;]\/\/\u8fed\u4ee3\u6cd5<\/p>\n<p>typedef struct _Range {<br \/>\n\tint start, end;<br \/>\n} Range;<br \/>\nRange new_Range(int s, int e) {<br \/>\n\tRange r;<br \/>\n\tr.start = s;<br \/>\n\tr.end = e;<br \/>\n\treturn r;<br \/>\n}<br \/>\nvoid swap(int *x, int *y) {<br \/>\n\tint t = *x;<br \/>\n\t*x = *y;<br \/>\n\t*y = t;<br \/>\n}<br \/>\nvoid quick_sort(int arr[], const int len) {<br \/>\n\tif (len &lt;= 0)<br \/>\n\t\treturn; \/\/\u907f\u514dlen\u7b49\u65bc\u8ca0\u503c\u6642\u5ba3\u544a\u5806\u758a\u9663\u5217\u7576\u6a5f<br \/>\n\t\/\/r[]\u6a21\u64ec\u5806\u758a,p\u70ba\u6578\u91cf,r[p++]\u70bapush,r[&#8211;p]\u70bapop\u4e14\u53d6\u5f97\u5143\u7d20<br \/>\n\tRange r[len];<br \/>\n\tint p = 0;<br \/>\n\tr[p++] = new_Range(0, len &#8211; 1);<br \/>\n\twhile (p) {<br \/>\n\t\tRange range = r[&#8211;p];<br \/>\n\t\tif (range.start &gt;= range.end)<br \/>\n\t\t\tcontinue;<br \/>\n\t\tint mid = arr[range.end];<br \/>\n\t\tint left = range.start, right = range.end &#8211; 1;<br \/>\n\t\twhile (left &lt; right) {<br \/>\n\t\t\twhile (arr[left] &lt; mid &amp;&amp; left &lt; right)<br \/>\n\t\t\t\tleft++;<br \/>\n\t\t\twhile (arr[right] &gt;= mid &amp;&amp; left &lt; right)<br \/>\n\t\t\t\tright&#8211;;<br \/>\n\t\t\tswap(&amp;arr[left], &amp;arr[right]);<br \/>\n\t\t}<br \/>\n\t\tif (arr[left] &gt;= arr[range.end])<br \/>\n\t\t\tswap(&amp;arr[left], &amp;arr[range.end]);<br \/>\n\t\telse<br \/>\n\t\t\tleft++;<br \/>\n\t\tr[p++] = new_Range(range.start, left &#8211; 1);<br \/>\n\t\tr[p++] = new_Range(left + 1, range.end);<br \/>\n\t}<br \/>\n}<br \/>\n\/\/\u905e\u6b78\u6cd5<\/p>\n<p>void swap(int *x, int *y) {<br \/>\n\tint t = *x;<br \/>\n\t*x = *y;<br \/>\n\t*y = t;<br \/>\n}<br \/>\nvoid quick_sort_recursive(int arr[], int start, int end) {<br \/>\n\tif (start &gt;= end)<br \/>\n\t\treturn;\/\/\u9019\u662f\u70ba\u4e86\u9632\u6b62\u5ba3\u544a\u5806\u758a\u9663\u5217\u6642\u7576\u6a5f<br \/>\n\tint mid = arr[end];<br \/>\n\tint left = start, right = end &#8211; 1;<br \/>\n\twhile (left &lt; right) {<br \/>\n\t\twhile (arr[left] &lt; mid &amp;&amp; left &lt; right)<br \/>\n\t\t\tleft++;<br \/>\n\t\twhile (arr[right] &gt;= mid &amp;&amp; left &lt; right)<br \/>\n\t\t\tright&#8211;;<br \/>\n\t\tswap(&amp;arr[left], &amp;arr[right]);<br \/>\n\t}<br \/>\n\tif (arr[left] &gt;= arr[end])<br \/>\n\t\tswap(&amp;arr[left], &amp;arr[end]);<br \/>\n\telse<br \/>\n\t\tleft++;<br \/>\n    if (left) {<br \/>\n\t    quick_sort_recursive(arr, start, left &#8211; 1);<br \/>\n\t    quick_sort_recursive(arr, left + 1, end);<br \/>\n    } else {<br \/>\n        quick_sort_recursive(arr, left + 1, end);<br \/>\n    }<br \/>\n}<br \/>\nvoid quick_sort(int arr[], int len) {<br \/>\n\tquick_sort_recursive(arr, 0, len &#8211; 1);<br \/>\n}<br \/>\n[\/code][\/hide]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[hide][code lang=&#8221;c&#8221;]\/\/\u8fed\u4ee3\u6cd5 typedef struct _ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"class_list":["post-44","post","type-post","status-publish","format-standard","hentry","category-1"],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8UC2c-I","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/44","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=44"}],"version-history":[{"count":2,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":58,"href":"https:\/\/haoyuan.info\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions\/58"}],"wp:attachment":[{"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haoyuan.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}