count_inversions in an integer list
来源:互联网 发布:怎么在淘宝上改评价 编辑:程序博客网 时间:2024/05/24 15:40
count = 0def merge_sort(li): if len(li) < 2: return li m = len(li) / 2 return merge(merge_sort(li[:m]), merge_sort(li[m:])) def merge(l, r): global count result = [] i = j = 0 while i < len(l) and j < len(r): if l[i] < r[j]: result.append(l[i]) i += 1 else: result.append(r[j]) count = count + (len(l) - i) j += 1 result.extend(l[i:]) result.extend(r[j:]) return resultfilename = 'Integer.txt'unsorted = []inFile = open(filename, 'r')lines = inFile.readlines()for i in lines: content = i.strip('\n') unsorted.append(int(content))merge_sort(unsorted)print count
0 0
- count_inversions in an integer list
- Count set bits in an integer
- Initialize List<List<Integer>> in Java 怎么初始化List<List<Integer>>
- Get ancestors list in an XML document
- java 2.6** Summing the digits in an integer
- Counting-the-number-of-set-bits-in-an-integer
- How to convert List<Integer> to int[] in Java?
- Shuffle an Array or a List - Algorithm in Java
- Get an object attributes list in Objective-C
- Always an Integer LA4119
- uva1069 - Always an integer
- SQL Error:An aggregate may not appear in the set list of an UPDATE statement.
- A smart way to count the ONEs in an integer's binary form representation
- How can I convert a floating-point value to an integer in C?
- How Do I Convert an Integer to a String in Excel VBA
- Ten Ways to Check if an Integer Is a Power Of Two in C
- How to find number of a specific integer in an array of Fixnums ruby
- Distinguish between index of a decimal number and integer inside an array in Ruby?
- 开源许可证
- Matlab最小生成树示例
- android 摇晃工具箱
- 多核技术与并发多线程
- java 服务器自动生成plist文件案例
- count_inversions in an integer list
- Boolean类型
- xml-读写查-基本步骤
- 打开对话框和保存对话框(文件操作)
- 【转】如何学习Javascript
- 20140514,微软5月14日发布8个安全补丁
- 微信公众平台自定义脚本
- LeetCode 008 String to Integer (atoi)
- Python 中的文件读写(二)