{"id":70,"date":"2012-11-06T20:28:06","date_gmt":"2012-11-07T04:28:06","guid":{"rendered":"http:\/\/blog.ls-al.com\/?p=70"},"modified":"2012-11-06T20:28:06","modified_gmt":"2012-11-07T04:28:06","slug":"python-simple-sort","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/python-simple-sort\/","title":{"rendered":"Python Simple Sort"},"content":{"rendered":"

Quick sort routine...<\/p>\n

\r\ndef sort(array):\r\n  if len(array) <= 1: return array\r\n  mid = len(array) \/\/ 2\r\n  return merge (sort(array[0:mid]), sort(array[mid:]))\r\n\r\n# this may not be the most thoroughly idiomatic python, or the\r\n# most efficient merge (it duplicates data when \"Transmitting\")\r\n# but it works\r\ndef merge(left, right):\r\n    merged = []\r\n\r\n    i = 0\r\n    j = 0\r\n    while(len(merged) < len(left)+len(right)):\r\n        if left[i] < right[j]:\r\n            merged.append(left[i])\r\n            i += 1\r\n            if i == len(left):\r\n                # Knuth, TaoCP Vol 3 5.2.4 Calls this the \"transmit\"       \r\n                y = right[j:]\r\n                for x in y:\r\n                    merged.append(x)\r\n                break\r\n        else:\r\n            merged.append(right[j])\r\n            j += 1\r\n            if j == len(right):\r\n                y = left[i:]\r\n                for x in y:\r\n                    merged.append(x)\r\n                break\r\n\r\n    return merged\r\n\r\na=[1,3,2,4]\r\nb=sort(a)\r\nprint b\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

Quick sort routine… def sort(array): if len(array)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-70","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/70","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=70"}],"version-history":[{"count":0,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}