Merge sort by using recursive strategy, i.e. divide and conquer.

def merge(left,right):
result = []
i,j =,
while i < len(left) and j < len(right):
if left[i]<right[j]:
result.append(left[i])
i +=
else:
result.append(right[j])
j +=
result += left[i:]
result += right[j:]
return result def merge_Sort(seq):
if len(seq)<=:
return seq
mid = len(seq)/
left = merge_Sort(seq[:mid])
right = merge_Sort(seq[mid:])
return merge(left,right) seq = [, , , , , , , , , , , , , , , , , , , , ]
merge_Sort(seq)
def ins_sort_rec(seq,i):
if i==: return
ins_sort_rec(seq,i-)
j = i
while j > and seq[j - ] > seq[j]:
seq[j -],seq[j] = seq[j], seq[j-]
j -=
return seq seqq = [,,,,,,,,,,,,,] a = ins_sort_rec(seqq,len(seqq)-)
a def insertsort(seq):
for i in range(,len(seq)):
j = i
while seq[j] <seq[j-] and j>:
seq[j],seq[j-] = seq[j-],seq[j]
j -=
return seq b = insertsort(seqq)
b def changesort(seq):
count = True
while count:
count = False
for i in range(,len(seq)):
if seq[i]<seq[i-]:
seq[i],seq[i-] = seq[i-],seq[i]
count =True
return seq ls = [,,,,,,,,,,,,,]
c = changesort(ls)
c seqq = [,,,,,,,,,,,,,] def selectsort(ls):
for i in range(len(ls)-):
k = i
for j in range(i,len(ls)):
if ls[k] >ls[j]:
k = j
if k !=i:
ls[i],ls[k]=ls[k],ls[i]
return ls
selectsort(seqq)

 

Sorting Algorithms的更多相关文章

  1. JavaScript 排序算法(JavaScript sorting algorithms)

    JavaScrip 排序算法(JavaScript Sorting Algorithms) 基础构造函数 以下几种排序算法做为方法放在构造函数里. function ArrayList () { va ...

  2. [Algorithms] Sorting Algorithms (Insertion Sort, Bubble Sort, Merge Sort and Quicksort)

    Recently I systematicall review some sorting algorithms, including insertion sort, bubble sort, merg ...

  3. Summary: sorting Algorithms

    Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item a ...

  4. Basic Sorting Algorithms

    *稳定指原本数列中相同的元素的相对前后位置在排序后不会被打乱 快速排序(n*lgn 不稳定):数组中随机选取一个数x(这里选择最后一个),将数组按比x大的和x小的分成两部分,再对剩余两部分重复这个算法 ...

  5. 算法的稳定性(Stability of Sorting Algorithms)

    如果具有同样关键字的纪录的在排序前和排序后相对位置保持不变.一些算法本身就是稳定的,如插入排序,归并排序,冒泡排序等,不稳定的算法有堆排序,快速排序等. 然而,一个本身不稳定的算法通过一点修正也能变成 ...

  6. 1306. Sorting Algorithm 2016 12 30

    1306. Sorting Algorithm Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description One of the f ...

  7. [zt]Which are the 10 algorithms every computer science student must implement at least once in life?

    More important than algorithms(just problems #$!%), the techniques/concepts residing at the base of ...

  8. Top 10 Algorithms for Coding Interview--reference

    By X Wang Update History:Web Version latest update: 4/6/2014PDF Version latest update: 1/16/2014 The ...

  9. 转:Top 10 Algorithms for Coding Interview

    The following are top 10 algorithms related concepts in coding interview. I will try to illustrate t ...

随机推荐

  1. C语言 分割字符串

    对指针的操作有点迷糊 只好采用下面一些比较low的手段 char str[100]; char delims[] = ";"; char *result = NULL; sprin ...

  2. particles.js使用及配置

    particles.js使用及配置 参考:http://blog.csdn.net/csdn_yudong/article/details/53128570 这个项目中有提供demo,可以直接下载这个 ...

  3. IDEA 的Class not found: "..."Empty test suite

    Junit测试的时候出现  IDEA 的Class not found: "..."Empty test suite问题. 尝试一下解决方法: 第一种方法: 1.modules&g ...

  4. idea关于热部署插件JRebel的使用教程

    1. idea安装JRebel热部署插件 在1处输入jrebel然后在3处点击install安装按钮就可以了,安装好以后如下图: 2. 激活JRebel help -> JRebel -> ...

  5. java中如何认定一个变量和方法

    对于变量,用变量名就可以认定.对于a ,你不能要求它既是int,又是double.这是错误的: 同理,对于方法,它的方法签名是:方法名+参数     通过签名,已经认定一个方法.你不能要求一个方法有多 ...

  6. Promise的.then .catch

    定义一个promise 调用promise  如果promise的状态为resolve 则 执行 .then   否则执行.catch 可以有多个.then  会按顺序执行 axios.post  可 ...

  7. 查看GPU占用率以及指定GPU加速程序

    GPU占用率查看: 方法一:任务管理器 如图,GPU0和GPU1的占用率如下显示. 方法二:GPU-Z软件       下面两个GPU,上面是GPU0,下面是GPU1 sensors会话框里的GPU  ...

  8. QT json字符串生成和解析

    1         QT json字符串生成和解析 1.1  QT Json解析流程 (1)  字符串转化为QJsonDocument QJsonParseError json_error; QJso ...

  9. git stash命令

    命令:git stash 1.使用git stash 保存当前的工作现场, 那么就可以切换到其他分支进行工作,或者在当前分支上完成其他紧急的工作,比如修订一个bug测试提交. 2.如果一个使用了一个g ...

  10. java学习视频

    随着信息化的发展,IT行业变得越来火,在开发领域,Java语言在是市面上很受欢迎的编程语言,很多初学者不知道从何学起,为了找资源浪费大量时间,而我就将自己的寻找资源分享给大家,让大家能够更加便捷的学习 ...