mergesort_arithmetic_python
def merge(a, b):
c = []
h = j = 0
while j < len(a) and h < len(b):
if a[j] < b[h]:
c.append(a[j])
j += 1
else:
c.append(b[h])
h += 1 if j == len(a):
for i in b[h:]:
c.append(i)
else:
for i in a[j:]:
c.append(i) return c def merge_sort(lists):
if len(lists) <= 1:
return lists
middle = int(len(lists)/2)
left = merge_sort(lists[:middle])
right = merge_sort(lists[middle:])
return merge(left, right) if __name__ == '__main__':
a = [4, 7, 8, 3, 5, 9]
print(merge_sort(a))
mergesort_arithmetic_python的更多相关文章
随机推荐
- centos7 下 apache nginx squid https正向代理 代理服务器
apache yum install httpd mod_ssl -y vim /etc/httpd/conf.d/ssl.conf Listen https <VirtualHost *:&g ...
- sendmail 发送邮件 zabbix 自定义报警
配合zabbix 触发脚本 达到自定义报警目的 #!/bin/bash # Created : 2015.12.08 # Updated : 2015.12.08 # Author : sanmuya ...
- [LeetCode] 584. Find Customer Referee_Easy tag: SQL
Given a table customer holding customers information and the referee. +------+------+-----------+ | ...
- IIS预编译提升加载速度
当我们把网站部署在IIS7或IIS6S的时候,每当IIS或是ApplicationPool重启后,第一次请求网站反应总是很慢,原因大家都知道(不知道可以参考这个动画说明ASP.NET网页第一个Requ ...
- 数据分析与挖掘 - R语言:贝叶斯分类算法(案例三)
案例三比较简单,不需要自己写公式算法,使用了R自带的naiveBayes函数. 代码如下: > library(e1071)> classifier<-naiveBayes(iris ...
- Permission denied: user=root, access=WRITE, inode="/":hadoopuser:supergroup:drwxr-xr-x
提示往HDFS写文件是不容许的. 在conf/hdfs-site.xml中加入: <property> <name>dfs.permissions</name> & ...
- es6generator
yield语句 由于Generator函数返回的遍历器对象,只有调用next方法才会遍历下一个内部状态,所以其实提供了一种可以暂停执行的函数.yield语句就是暂停标志. yield语句只能用在 Ge ...
- LeetCode122.买卖股票的最佳时机II
给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 设计一个算法来计算你所能获取的最大利润.你可以尽可能地完成更多的交易(多次买卖一支股票). 注意:你不能同时参与多笔交易(你必须在再次 ...
- equals和==的区别小结
==: == 比较的是变量(栈)内存中存放的对象的(堆)内存地址,用来判断两个对象的地址是否相同,即是否是指相同一个对象.比较的是真正意义上的指针操作. 1.比较的是操作符两端的操作数是否是同一个对象 ...
- DataGridView常用属性和方法
DataGridView常用属性: 只读属性设定 datagridview.ReadOnly = True 行自动追加 datagridview.AllowUserToAddRows = ...