一、 实验目的及任务
用分治法解决数组排序
二、 实验环境
c++或java
三、 问题描述
Input : 一个数组
Output:自小到大排列的数组
四、 编程任务
对于一个数组,用分治法的思想将其按照从小到大排列。
五、 数据输入
随机产生1000以上的数据,放入输入文件input.txt
六、 结果输出
比如数组 A ={3, 41, 52, 26, 38, 57, 9, 49},输出为{3,9,26,38,41,49.51,57}。
七、 实验报告内容
程序主要代码
import math
import ioTool
#合并
def merge(A, B, s):
Aindex = 0 #A下标
Bindex = 0 #B下标
while Aindex + Bindex < len(s):
#如果
if Bindex == len(B) or (Aindex B[Bindex]):
s[Aindex+Bindex] = A[Aindex]
Aindex = Aindex + 1
else:
s[Aindex+Bindex] = B[Bindex]
Bindex = Bindex + 1
return s
#拆分
num = 0
def merge_soft(s):
global num
n = le