{"id":865,"date":"2018-07-17T18:18:54","date_gmt":"2018-07-17T10:18:54","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=865"},"modified":"2018-07-17T18:18:54","modified_gmt":"2018-07-17T10:18:54","slug":"%e7%ac%ac%e5%8d%81%e5%9b%9b%e8%ae%b2%ef%bc%9a%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/python\/865\/","title":{"rendered":"\u7b2c\u5341\u56db\u8bb2\uff1a\u6392\u5e8f"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\"># -*- coding:utf-8 -*-\n# \u6392\u5e8f\n# \u63d2\u5165\u6392\u5e8f\ndef insertSort(originList):\n    sortedList = []\n    for i in range(0, len(originList)):\n        if len(sortedList) == 0:\n            sortedList.append(originList[i])\n            continue\n            # \u5012\u67e5\n            # for j in range(len(sortedList) - 1, -1, -1):\n            #     if sortedList[j] &lt;= originList[i]:\n            #         sortedList.insert(j + 1, originList[i])\n            #         break\n            #     if j == 0:\n            #         sortedList.insert(0, originList[i])\n            # \u6b63\u67e5\n        for j in range(0, len(sortedList)):\n            if sortedList[j] &gt;= originList[i]:\n                sortedList.insert(j, originList[i])\n                break\n            if j == len(sortedList) - 1:\n                sortedList.insert(len(sortedList), originList[i])\n    originList[:] = sortedList[:]\noriginList = [5, 3, 1, 7, 9, 8]\ninsertSort(originList)\n# print \"insert\"\n# print originList\n# \u5192\u6ce1\u6392\u5e8f\n# \u5feb\u901f\u6392\u5e8f(\u5f39\u5e55\u8fd9\u4e2a\u597d\u50cf\u6709\u95ee\u9898\uff0c\u4f46\u662f\u53ef\u4ee5\u5b9e\u73b0\uff0c\u6211\u611f\u89c9\u6ca1\u95ee\u9898 ojbk\ndef quickSort(originList, start, end):\n    if start &gt;= end:\n        return\n    left = start\n    right = end\n    flagIndex = left\n    while left &lt; right:\n        while right &gt; left:\n            if originList[right] &lt; originList[flagIndex]:\n                originList[right], originList[flagIndex] = originList[flagIndex], originList[right] # \u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u7684\u4f4d\u7f6e\n                flagIndex = right   # \u7ee7\u7eed\u5c06\u6bd4\u8f83\u503c\u7d22\u5f15\u66f4\u6362\u4ee5\u4fdd\u8bc1\u6bd4\u8f83\u503c\u4e0d\u53d8\n                break\n            right -= 1\n        while left &lt; right:\n            if originList[left] &gt; originList[flagIndex]:\n                originList[left], originList[flagIndex] = originList[flagIndex], originList[left]\n                flagIndex = left\n                break\n            left += 1\n    quickSort(originList, start, flagIndex)\n    quickSort(originList, flagIndex + 1, end)\noriginList = [5, 3, 1, 7, 9, 8]\nquickSort(originList, 0, len(originList) - 1)\n# print \"quick\"\n# print originList\n# \u5f52\u5e76\u6392\u5e8f\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p># -*- coding:utf-8 -*- # \u6392\u5e8f # \u63d2\u5165\u6392\u5e8f def insertSort( [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[24],"tags":[],"views":3753,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/865"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=865"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/865\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=865"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}