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

  1. def merge(left,right):
  2. result = []
  3. i,j =,
  4. while i < len(left) and j < len(right):
  5. if left[i]<right[j]:
  6. result.append(left[i])
  7. i +=
  8. else:
  9. result.append(right[j])
  10. j +=
  11. result += left[i:]
  12. result += right[j:]
  13. return result
  14.  
  15. def merge_Sort(seq):
  16. if len(seq)<=:
  17. return seq
  18. mid = len(seq)/
  19. left = merge_Sort(seq[:mid])
  20. right = merge_Sort(seq[mid:])
  21. return merge(left,right)
  22.  
  23. seq = [, , , , , , , , , , , , , , , , , , , , ]
  24. merge_Sort(seq)
  1. def ins_sort_rec(seq,i):
  2. if i==: return
  3. ins_sort_rec(seq,i-)
  4. j = i
  5. while j > and seq[j - ] > seq[j]:
  6. seq[j -],seq[j] = seq[j], seq[j-]
  7. j -=
  8. return seq
  9.  
  10. seqq = [,,,,,,,,,,,,,]
  11.  
  12. a = ins_sort_rec(seqq,len(seqq)-)
  13. a
  14.  
  15. def insertsort(seq):
  16. for i in range(,len(seq)):
  17. j = i
  18. while seq[j] <seq[j-] and j>:
  19. seq[j],seq[j-] = seq[j-],seq[j]
  20. j -=
  21. return seq
  22.  
  23. b = insertsort(seqq)
  24. b
  25.  
  26. def changesort(seq):
  27. count = True
  28. while count:
  29. count = False
  30. for i in range(,len(seq)):
  31. if seq[i]<seq[i-]:
  32. seq[i],seq[i-] = seq[i-],seq[i]
  33. count =True
  34. return seq
  35.  
  36. ls = [,,,,,,,,,,,,,]
  37. c = changesort(ls)
  38. c
  39.  
  40. seqq = [,,,,,,,,,,,,,]
  41.  
  42. def selectsort(ls):
  43. for i in range(len(ls)-):
  44. k = i
  45. for j in range(i,len(ls)):
  46. if ls[k] >ls[j]:
  47. k = j
  48. if k !=i:
  49. ls[i],ls[k]=ls[k],ls[i]
  50. return ls
  51. selectsort(seqq)
  1.  
  1.  

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. 转载:mysql存储过程讲解

    记录MYSQL存储过程中的关键语法: DELIMITER // 声明语句结束符,用于区分; CEATE PROCEDURE demo_in_parameter(IN p_in int) 声明存储过程 ...

  2. 在mybatis中resultMap与resultType的区别

    MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMapresultType是直接表示返回类型的,而resultMap则是对外部ResultMa ...

  3. URAL 1004 Sightseeing Trip(floyd求最小环+路径输出)

    https://vjudge.net/problem/URAL-1004 题意:求路径最小的环(至少三个点),并且输出路径. 思路: 一开始INF开大了...无限wa,原来相加时会爆int... 路径 ...

  4. Windows下使用命令安装Python的scipy库出错的解决

    平时使用Python都是在Sublime下使用,不想使用IDE.使用各种库时安装也就是使用pip安装即可.来说说今天自己遇到的一个问题:使用scipy数学库时,使用命令: pip install sc ...

  5. Python open 对应的参数

  6. table固定列的宽度,超出部分用…代替(针对普通table和antd)

    一. 实现思路 我们都知道让溢出内容变成...,只需要以下: overflow: hidden; text-overflow:ellipsis; white-space: nowrap; 表格里的内容 ...

  7. JaveWeb 公司项目(1)----- 使Div覆盖另一个Div完成切换效果

    最近在做网页,用的是CSS+DIV的布局方法,搭建了一个简易的界面,大体上分为三个部分,如图所示: 左侧的为主功能导航栏,右侧是具体的功能实现,下方是固定的版权声明,单击左边不同的导航按钮,在div中 ...

  8. Java离线人脸识别SDK 支持arcface 2.0 最新版

    虹软人脸识别SDK之Java版,支持SDK 1.1+,以及当前最新版本2.0,滴滴,抓紧上车! JDK SDK Win release license status 前言 由于业务需求,最近跟人脸识别 ...

  9. 滑动拼图 Sliding Puzzle

    2018-09-09 22:01:02 问题描述: 问题求解: 问题很Interesting,其实本质就是解空间遍历,使用BFS就可以很快的予以解决~ public int slidingPuzzle ...

  10. 如何调节tomcat初始内存

    1.linux下调节tomcat初始内存大小 linux下tomcat的运行文件为catalina.sh,打开文件,在文件靠近顶部找到“ JAVA_OPTS ”字样,在它后面添加如下内容即可 # JA ...