I wrote a blog about Quick Sort before. Let's talk more about it.

  If you don't think that the implementation in the blog mentioned is easy to remember and understand.

You can send your implementation to me by E-mail(lxw.ucas@gmail.com). Now let's look at some other

implementations that are not so amazing:

  A new implementation in python is shown here:

def qs(arr):
if not arr:
return []
low = []
high = []
for x in arr[1:]:
if x <= arr[0]:
low.append(x)
else:
high.append(x)
low = qs(low)
high = qs(high)
return low + arr[:1] + high # low + arr[0] + high is NOT OK! --> ERROR PROMPT: 'can only concatenate list(not int) to list'

  It seemed not so amazing and easy to understand as the former one. But it's ok as well. : ) Let's look

at another new implementation in python:

def quickSort(arr, start, end):
if start >= end: # EXIT
return
i = start
j = end
target = arr[i]
while i < j:
while arr[i] <= target and i < end:
i += 1
while arr[j] > target and j > start:
j -= 1
if i < j:
arr[i], arr[j] = arr[j], arr[i]
arr[start] = arr[j]
arr[j] = target
quickSort(arr, start, j - 1)
quickSort(arr, j + 1, end)

  Now, which way of implementation do you prefer? Do you think the implementation in the blog mentioned

is easy to understand and remember?

QuickSort again的更多相关文章

  1. quickSort算法导论版实现

    本文主要实践一下算法导论上的快排算法,活动活动. 伪代码图来源于 http://www.cnblogs.com/dongkuo/p/4827281.html // imp the quicksort ...

  2. Javascript算法系列之快速排序(Quicksort)

    原文出自: http://www.nczonline.net/blog/2012/11/27/computer-science-in-javascript-quicksort/ https://gis ...

  3. JavaScript 快速排序(Quicksort)

    "快速排序"的思想很简单,整个排序过程只需要三步: (1)在数据集之中,选择一个元素作为"基准"(pivot). (2)所有小于"基准"的元 ...

  4. QuickSort 快速排序 基于伪代码实现

    本文原创,转载请注明地址 http://www.cnblogs.com/baokang/p/4737492.html 伪代码 quicksort(A, lo, hi) if lo < hi p ...

  5. quicksort

    快排.... void quicksort(int *a,int left,int right){ if(left >= right){ return ; } int i = left; int ...

  6. 随手编程---快速排序(QuickSort)-Java实现

    背景 快速排序,是在上世纪60年代,由美国人东尼·霍尔提出的一种排序方法.这种排序方式,在当时已经是非常快的一种排序了.因此在命名上,才将之称为"快速排序".这个算法是二十世纪的七 ...

  7. 算法实例-C#-快速排序-QuickSort

    算法实例 ##排序算法Sort## ### 快速排序QuickSort ### bing搜索结果 http://www.bing.com/knows/search?q=%E5%BF%AB%E9%80% ...

  8. python Quicksort demo

    __author__ = 'student' ''' quicksort step 1, choose one pivot, such as pivot=la[0] step 2, scan the ...

  9. 63.如何对单链表进行快排?和数组快排的分析与对比[quicksort of array and linked list]

    [本文链接] http://www.cnblogs.com/hellogiser/p/quick-sort-of-array-and-linked-list.html [题目] 单链表的特点是:单向. ...

  10. 这个代码怎么改??Help快速排序 quicksort

    #include<stdio.h>int a[101],n;void quicksort(int left,int right){     int i,j,t,temp;     if(l ...

随机推荐

  1. cookie转coontoin

    /// <summary> /// 一个到多个Cookie的字符串添加到CookieCollection集合中[isGood代码] /// </summary> /// < ...

  2. pdfBox 读取pdf文件

    1.引入maven依赖 <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pd ...

  3. 解决PHP编译cURL的reinstall the libcurl问题

    今天正好要用到PHP的curl功能,发现服务器上的PHP并没有配置curl,进而查询PHP官方文档,得知编译PHP时需要带上 –with-curl参数,才能把curl模块编译进去.我现在PHP已经编译 ...

  4. 大数据实战centos 6.7安装mysql5.7

    https://www.cnblogs.com/jr1260/p/6590232.html

  5. JavaScript 代码块

    JavaScript 语句通过代码块的形式进行组合. 块由左花括号开始,由右花括号结束. 块的作用是使语句序列一起执行. JavaScript 函数是将语句组合在块中的典型例子. 下面的例子将运行可操 ...

  6. 将Mac上的***代理共享给其他设备

    Windows版***带有Share over LAN功能,可以让一些不方便安装***客户端的设备一同“鸡犬升天”,如未越狱的iOS设备.但是 OS X 就没有这么幸运了,这时候你需要Privoxy助 ...

  7. ios UICollectionView reloadData无法更新的奇怪问题。

    报错    Assertion failure in -[UICollectionViewData invalidateItemsAtIndexPaths:] 近来偶尔用到UICollectionVi ...

  8. Ubuntu 14.04 Vim编辑文件的一般操作

    vim编辑文件的一般操作 1. vim #在命令行中输入vim,进入vim编辑器 2. i #按一下i键,下端显示 --INSERT-- #插入命令,在vim中可能任意字符都有作用 3. Esc #退 ...

  9. hdu2587(递推)

    目前做过的最纠结的一道递推题. 情况比较多,比较复杂... 这题最主要的还是要推出当m=2 时和m>2时,用什么方法最优. 给个数据 n=3,m=2   需要48 n=3,m=3 需要81 如果 ...

  10. HDU4027(Can you answer these queries?)

    题目链接:传送门 题目大意:有一个长度为n的数组,有m次操作,每次操作输入 v x y,v==0时x~y区间内的数都开平方并且向下取整,v==1时求x~y区间内所有数的和. 题目思路:long lon ...